📅  最后修改于: 2023-12-03 14:39:43.941000             🧑  作者: Mango
In C#, the Request.Url
property represents the Uniform Resource Identifier (URI) of the current HTTP request. It contains information about the scheme, host name, port number, path, query string, and fragment identifier of the requested resource.
The syntax to access the Request.Url
property is as follows:
Uri url = Request.Url;
The Request.Url
property is an instance of the System.Uri
class, which has the following properties:
http
or https
.The following code snippet demonstrates how to access and use the Request.Url
property in a C# web application:
Uri url = Request.Url;
string scheme = url.Scheme;
string host = url.Host;
int port = url.Port;
string path = url.AbsolutePath;
string query = url.Query;
string fragment = url.Fragment;
Console.WriteLine("Scheme: " + scheme);
Console.WriteLine("Host: " + host);
Console.WriteLine("Port: " + port);
Console.WriteLine("Path: " + path);
Console.WriteLine("Query: " + query);
Console.WriteLine("Fragment: " + fragment);
In this article, we have explored the Request.Url
property in C#. It is a useful property that allows developers to access the URI of the current HTTP request and extract information about its scheme, host, port, path, query string, and fragment identifier.