Home >Backend Development >C++ >How to Get the Current Page URL in ASP.NET using C#?

How to Get the Current Page URL in ASP.NET using C#?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2025-01-11 07:32:43217browse

How to Get the Current Page URL in ASP.NET using C#?

Retrieving the Current Page URL in C# for ASP.NET

Seeking the ability to retrieve the URL of the currently rendered page in an ASP.NET application? C# offers a straightforward solution:

Solution:

To obtain the complete absolute URL of the current page:

string url = HttpContext.Current.Request.Url.AbsoluteUri;

Additional Options:

If you require only a specific component of the URL:

  • Absolute Path:

    string path = HttpContext.Current.Request.Url.AbsolutePath;
  • Host Name:

    string host = HttpContext.Current.Request.Url.Host;

The above is the detailed content of How to Get the Current Page URL in ASP.NET using 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