Home >Backend Development >C++ >How to Get the Current Web Page URL in C#?

How to Get the Current Web Page URL in C#?

Barbara Streisand
Barbara StreisandOriginal
2025-01-11 06:22:40850browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn