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
Release: 2025-01-11 06:22:40
Original
910 people have browsed it

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:

string url = HttpContext.Current.Request.Url.AbsoluteUri;
Copy after login

Output:

<code>http://localhost:1302/TESTERS/Default6.aspx</code>
Copy after login

Request.Url.AbsolutePath

This property returns the absolute path of the current request, excluding protocol and server:

string path = HttpContext.Current.Request.Url.AbsolutePath;
Copy after login

Output:

<code>/TESTERS/Default6.aspx</code>
Copy after login

Request.Url.Host

This property returns the hostname of the server:

string host = HttpContext.Current.Request.Url.Host;
Copy after login

Output:

<code>localhost</code>
Copy after login

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 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template