Home >Backend Development >C++ >How Can I Retrieve the Current Page URL in C# ASP.NET?

How Can I Retrieve the Current Page URL in C# ASP.NET?

DDD
DDDOriginal
2025-01-11 06:38:43705browse

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

The

HttpContext.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!

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