Get the URL of the current page in C# - Asp.Net

Above code will return the absolute URL . "", 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):

How to get the URL of the current page in C# - Asp.Net

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 (?).
 (C) 2022    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.
SiteMap  | Terms  | About