A URI (Uniform Resource Identifier) serves as a standardized representation of a resource that is accessible to your application on the network. It acts as an identifier for locating and retrieving specific resources. Within your application, there are multiple ways to retrieve the host of a URL.
One approach is to utilize the Request object, which provides convenient methods for extracting information about the incoming request, including the host of the URL. Another option is to use the Uri class, which offers a range of properties and methods for parsing and manipulating URIs, including the ability to extract the host component of a given URL. By using these techniques, you can effectively obtain the host information needed for various networking operations within your application.
Get domain name of a url
string host = Request.Url.Host.ToLower();
Dim host As String = Request.Url.Host.ToLower()
Uri myUri = new Uri("http://forums.asp.net/t/1110512.aspx?");
string host = myUri.Host;
Dim myUri As New Uri("http://forums.asp.net/t/1110512.aspx?")
Dim host As String = myUri.Host
Or u can parse the url using regex
How to parse a domain from URL?
public partial class Form1 : Form
private void button1_Click(object sender, EventArgs e)
string sURL = "http://forums.asp.net/t/1110512.aspx?";
Regex rg = new Regex("://(?<host>([a-z\\d][-a-z\\d]*[a-z\\d]\\.)*[a-z][-a-z\\d]+[a-z])");
How to get domain part from URL
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim sURL As String = "http://forums.asp.net/t/1110512.aspx?"
Dim rg As New Regex("://(?<host>([a-z\d][-a-z\d]*[a-z\d]\.)*[a-z][-a-z\d]+[a-z])")
If rg.IsMatch(sURL) Then
Extract domain name from URL
An alternative approach that avoids the need for regular expressions or parsing is to utilize the following code snippet: