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

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

Linda Hamilton
Release: 2025-01-11 08:30:42
Original
222 people have browsed it

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

Accessing the Current Page URL in ASP.NET C#

This guide demonstrates how to obtain the URL of the currently displayed page within an ASP.NET application using C#.

Scenario:

Often, ASP.NET C# developers need to retrieve the current page's URL for various tasks.

Method:

The HttpRequest object offers several properties to access different parts of the URL:

<code class="language-csharp">string fullUrl = HttpContext.Current.Request.Url.AbsoluteUri;
string pagePath = HttpContext.Current.Request.Url.AbsolutePath;
string serverHost = HttpContext.Current.Request.Url.Host;</code>
Copy after login

Details:

  • AbsoluteUri: Returns the complete, absolute URL of the requested resource.
  • AbsolutePath: Provides the path portion of the URL, excluding the server's hostname.
  • Host: Specifies the hostname or IP address of the web server.

These properties allow you to extract specific URL components, offering flexibility in your code.

The above is the detailed content of How to Get the Current Page URL in ASP.NET C#?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template