There are a lot of instructions on Request. Url on the network, but I have practiced it to check whether the final result is consistent with that on the network.
1. Simple environment setup
On the local IIS, a website is configured with the host Name wjnhome.com, port 88, and a virtual directory pointing to the same site. The virtual directory name is virtual, and the host configuration is 127.0.0.1 wjnhome.com.
So the address is: http://wjnhome.com: 88/virtual/urldemo. aspx? Id = 2 # top
2. Write simple code
// The path of the virtual directory Response. write ("<strong> Request. applicationPath: </strong> "+ Request. applicationPath + "</br>"); // the physical path of the site (full path) Response. write ("<strong> Request. physicalPath: </strong> "+ Request. physicalPath + "</br>"); // The Directory of the physical path of the site. write ("<strong> DirectoryName: </strong>" + System. IO. path. getDirectoryName (Request. physicalPath) + "</br>"); // The Directory of the physical path of the site. write ("<strong> Request. physicalApplic AtionPath: </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 Response of the current page. write ("<strong> Request. currentExecutionFilePath: </strong> "+ Request. currentExecutionFilePath + "</br>"); // The Virtual Path Response of the current page. 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>"); // absolute path (excluding 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>"); // The host name Response of the URL. write ("<strong> Request. url. host: </strong> "+ Request. url. host + "</br>"); // URL port number Response. write ("<strong> Request. url. port: </strong> "+ Request. url. port + "</br>"); // host name + Port number Response. write ("<strong> Request. url. authority: </strong> "+ Request. url. authority + "</br>"); // obtain the Local Operating System Format of the file name Respon Se. write ("<strong> Request. url. localPath: </strong> "+ Request. url. localPath + "</br>"); // additional path information such as http://wjnhome.com: 88/UrlDemo. aspx/Hello? Id = 22 # top: Hello Response. write ("<strong> Request. pathInfo: </strong> "+ Request. pathInfo + "</br>"); // URL path and GET parameter Response. write ("<strong> Request. url. pathAndQuery: </strong> "+ Request. url. pathAndQuery + "</br>"); // GET parameter Response of the URL. write ("<strong> Request. url. query: </strong> "+ Request. url. query + "</br>"); // mainly refers to the http://wjnhome.com: 88/UrlDemo. aspx/Hello? Id = 22 # top in # top next. // But the value cannot be obtained normally, because the browser will not send this value to the server Response. write ("<strong> Request. url. fragment: </strong> "+ Request. url. fragment + "</br>"); // host name Response. write ("<strong> Request. url. dnsSafeHost: </strong> "+ Request. url. dnsSafeHost + "</br>"); // all Response of the URL. write ("<strong> Request. url. originalString: </strong> "+ Request. url. originalString + "</br>"); // In this case 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 Response of the Source Page is displayed. write ("<strong> Request. urlReferrer: </strong> "+ Request. urlReferrer + "</br>"); // each segment of the URI 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. aspx
DirectoryName:E: \ VsProject \ 201200420 \ UrlDemo
Request. PhysicalApplicationPath:E: \ VsProject \ 201200420 \ UrlDemo \
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://wjnhome.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://wjnhome.com: 88/virtual/urldemo. aspx? Id = 2
Request. Url. UserInfo:
Request. UrlReferrer:
Request. Url. Segment0:/
Request. Url. Segment1:Virtual/
Request. Url. Segment2:Urldemo. aspx