Get the URL of the current page in C# - Asp.Net
Above code will return the absolute URL . "www.facebook.com", for example, or it will return localhost URL if you are in the local environment. It is important to note that Url.AbsoluteUri does return anything after the “#” symbol.
Also you can extract different values from URL using HttpContext.Current.Request
If you just need the part between "http://" and the first slash:
If you want only the scheme and authority of the request (protocol, host and port):
To get the port no. of the URL:
To get AbsolutePath :
To get Application path :
To get Path and Query :
To get complete URL of Current page:
What does this code mean?
It takes the url of the current web request, including the query string , and then extracts the part before the query string i.e. the part before the question mark (?).