In Asp.net the corresponding meanings of each attribute of Request.Url are introduced

  • 2020-05-17 05:12:28
  • OfStack

1. Simple environment construction
A web site is configured on local IIS: host name wjnhome.com, port 88, then a virtual directory is created to point to the same site, virtual directory name virtual, host is configured to 127.0.0.1 wjnhome.com
So the address is: http: / / ofstack com: 88 / virtual urldemo aspx? id = 2 # top
Write simple code
 
// The path to the virtual directory  
Response.Write("<strong>Request.ApplicationPath:</strong>" + Request.ApplicationPath + "</br>"); 
// The physical path of the site ( The full path ) 
Response.Write("<strong>Request.PhysicalPath:</strong>" + Request.PhysicalPath + "</br>"); 
// Directory of the physical path to the site  
Response.Write("<strong>DirectoryName:</strong>" + System.IO.Path.GetDirectoryName(Request.PhysicalPath) + "</br>"); 
// Directory of the physical path to the site  
Response.Write("<strong>Request.PhysicalApplicationPath:</strong>" + Request.PhysicalApplicationPath + "</br>"); 
// The file name of the current page  
Response.Write("<strong>FileName:</strong>" + System.IO.Path.GetFileName(Request.PhysicalPath) + "</br>"); 
// The virtual path of the current page  
Response.Write("<strong>Request.CurrentExecutionFilePath:</strong>" + Request.CurrentExecutionFilePath + "</br>"); 
// The virtual path of the current page  
Response.Write("<strong>Request.FilePath:</strong>" + Request.FilePath + "</br>"); 
Response.Write("<strong>Request.Path:</strong>" + Request.Path + "</br>"); 
// The original URL 
Response.Write("<strong>Request.RawUrl:</strong>" + Request.RawUrl + "</br>"); 
// An absolute path ( Doesn't include parameters or anything ) 
Response.Write("<strong>Request.Url.AbsolutePath:</strong>" + Request.Url.AbsolutePath + "</br>"); 
// absolute URL 
Response.Write("<strong>Request.Url.AbsoluteUri:</strong>" + Request.Url.AbsoluteUri + "</br>"); 
//URL Protocol scheme  
Response.Write("<strong>Request.Url.Scheme:</strong>" + Request.Url.Scheme + "</br>"); 
//URL The host name  
Response.Write("<strong>Request.Url.Host:</strong>" + Request.Url.Host + "</br>"); 
//URL The port number  
Response.Write("<strong>Request.Url.Port:</strong>" + Request.Url.Port + "</br>"); 
// The host name + The port number  
Response.Write("<strong>Request.Url.Authority:</strong>" + Request.Url.Authority + "</br>"); 
// Gets the local operating system representation of the file name  
Response.Write("<strong>Request.Url.LocalPath:</strong>" + Request.Url.LocalPath + "</br>"); 
// Additional path information, for example http://ofstack.com:88/UrlDemo.aspx/Hello?id=22#top  So this is Hello 
Response.Write("<strong>Request.PathInfo:</strong>" + Request.PathInfo + "</br>"); 
//URL The path and GET parameter  
Response.Write("<strong>Request.Url.PathAndQuery:</strong>" + Request.Url.PathAndQuery + "</br>"); 
//URL the GET parameter  
Response.Write("<strong>Request.Url.Query:</strong>" + Request.Url.Query + "</br>"); 
// Mainly refers to http://ofstack.com:88/UrlDemo.aspx/Hello?id=22#top In the # At the back of the top .  
// but 1 Normally you cannot get the value because the browser will not send it to the server  
Response.Write("<strong>Request.Url.Fragment:</strong>" + Request.Url.Fragment + "</br>"); 
// The host name  
Response.Write("<strong>Request.Url.DnsSafeHost:</strong>" + Request.Url.DnsSafeHost + "</br>"); 
//URL All of the  
Response.Write("<strong>Request.Url.OriginalString:</strong>" + Request.Url.OriginalString + "</br>"); 
// This kind of situation  Uri uriAddress = new Uri ("http://user:password@www.contoso.com/index.htm ") Console.WriteLine(uriAddress.UserInfo); 
Response.Write("<strong>Request.Url.UserInfo:</strong>" + Request.Url.UserInfo + "</br>"); 
// When you jump from a page, the value of the source page is displayed  
Response.Write("<strong>Request.UrlReferrer:</strong>" + Request.UrlReferrer + "</br>"); 
//URI Each of the 1 Period of  
for (var i = 0; i < Request.Url.Segments.Length;i++ ) 
{ 
Response.Write("<strong>Request.Url.Segment" + i + ":</strong>" + Request.Url.Segments[i] + "</br>"); 
} 

3. Output results
Request. ApplicationPath: / virtual
Request. PhysicalPath: E: \ VsProject \ 201200420 \ UrlDemo \ UrlDemo \ urldemo aspx
DirectoryName: E: \ VsProject \ 201200420 \ UrlDemo \ UrlDemo
Request. PhysicalApplicationPath: E: \ VsProject \ \ UrlDemo \ UrlDemo \ 201200420
FileName: urldemo aspx
Request. CurrentExecutionFilePath: / virtual/urldemo aspx
Request. FilePath: / virtual/urldemo aspx
Request. Path: / virtual/urldemo aspx
Request. RawUrl: / virtual/urldemo aspx? id = 2
Request. Url. AbsolutePath: / virtual/urldemo aspx
Request. Url. AbsoluteUri: http: / / ofstack com: 88 / virtual urldemo aspx? id = 2
Request. Url. Scheme: http
Request. Url. Host: wjnhome com
Request. Url. Port: 88
Request. Url. Authority: wjnhome. com: 88
Request. Url. LocalPath: / virtual/urldemo aspx
Request. PathInfo:
Request. Url. PathAndQuery: / virtual/urldemo aspx? id = 2
Request. Url. Query:? id = 2
Request. Url. Fragment:
Request. Url. DnsSafeHost: wjnhome com
Request. Url. OriginalString: http: / / ofstack com: 88 / virtual urldemo aspx? id = 2
Request. Url. UserInfo:
Request. UrlReferrer:
Request. Url. Segment0: /
Request. Url. Segment1: virtual /
Request. Url. Segment2: urldemo aspx

Author: wjn

Related articles: