Home >Backend Development >C++ >How Can I Retrieve the Current Page URL in C# ASP.NET?
Get the current page URL in C#
ASP.NET applications written in C# often need to obtain the URL of the current active page. Several methods can be used for this purpose.
Method 1: Use HttpContext
TheHttpContext.Current.Request.Url
attribute provides access to the current page URL. It provides three different values:
AbsoluteUri
: Returns the complete URL, including scheme, hostname and path. AbsolutePath
: Returns the path portion of the URL, excluding scheme and hostname. Host
: Provide the hostname or IP address of the server. <code class="language-csharp">string url = HttpContext.Current.Request.Url.AbsoluteUri; // http://localhost:1302/TESTERS/Default6.aspx string path = HttpContext.Current.Request.Url.AbsolutePath; // /TESTERS/Default6.aspx string host = HttpContext.Current.Request.Url.Host; // localhost</code>
The above is the detailed content of How Can I Retrieve the Current Page URL in C# ASP.NET?. For more information, please follow other related articles on the PHP Chinese website!