Home >Backend Development >C++ >How to Get the Current Web Page URL in C#?
Get the current webpage URL in C#
In ASP.NET development, getting the URL of the current web page is a common task. C# provides several methods to retrieve this information:
Request.Url.AbsoluteUri
This property returns the absolute URI of the current request, including protocol, server and path:
<code class="language-csharp">string url = HttpContext.Current.Request.Url.AbsoluteUri;</code>
Output:
<code>http://localhost:1302/TESTERS/Default6.aspx</code>
Request.Url.AbsolutePath
This property returns the absolute path of the current request, excluding protocol and server:
<code class="language-csharp">string path = HttpContext.Current.Request.Url.AbsolutePath;</code>
Output:
<code>/TESTERS/Default6.aspx</code>
Request.Url.Host
This property returns the hostname of the server:
<code class="language-csharp">string host = HttpContext.Current.Request.Url.Host;</code>
Output:
<code>localhost</code>
The above is the detailed content of How to Get the Current Web Page URL in C#?. For more information, please follow other related articles on the PHP Chinese website!