Reprint Original Address
Http://blog.miniasp.com/post/2008/02/10/How-Do-I-Get-Paths-and-URL-fragments-from-the-HttpRequest-object.aspx
Web address: Http://localhost:1897/News/Press/Content.aspx/123?id=1#toc |
Request.applicationpath |
/ |
Request.PhysicalPath |
D:\Projects\Solution\web\News\Press\Content.aspx |
System.IO.Path.GetDirectoryName (Request.PhysicalPath) |
D:\Projects\Solution\web\News\Press |
Request.physicalapplicationpath |
D:\Projects\Solution\web\ |
System.IO.Path.GetFileName (Request.PhysicalPath) |
Content.aspx |
Request.currentexecutionfilepath |
/news/press/content.aspx |
Request.filepath |
/news/press/content.aspx |
Request.path |
/news/press/content.aspx/123 |
Request.rawurl |
/news/press/content.aspx/123?id=1 |
Request.Url.AbsolutePath |
/news/press/content.aspx/123 |
Request.Url.AbsoluteUri |
Http://localhost:1897/News/Press/Content.aspx/123?id=1 |
Request.Url.Scheme |
http |
Request.Url.Host |
localhost |
Request.Url.Port |
1897 |
Request.Url.Authority |
localhost:1897 |
Request.Url.LocalPath |
/news/press/content.aspx/123 |
Request.pathinfo |
/123 |
Request.Url.PathAndQuery |
/news/press/content.aspx/123?id=1 |
Request.Url.Query |
? id=1 |
Request.Url.Fragment |
|
Request.Url.Segments |
/ news/ press/ content.aspx/ 123 |
The following sections are reproduced in the Source: http://www.cnblogs.com/aspnetjia/p/5222744.html (http://www.aspnetjia.com)
Assuming the current page full address is: Http://www.test.com/aaa/bbb.aspx?id=5&name=kelli
"/HTTP" is the protocol name
"Www.test.com" is the domain name
"AAA" is the station name.
"Bbb.aspx" is the page name (file name)
"Id=5&name=kelli" is a parameter
"1" gets the full URL (protocol name + domain + site name + file name + parameter)
String url=request.url.tostring ();
Url= Http://www.test.com/aaa/bbb.aspx?id=5&name=kelli
"2" gets the site name + page name + parameters:
String Url=request.rawurl;
(or string url=request.url.pathandquery;)
Url=/aaa/bbb.aspx?id=5&name=kelli
"3" Get Site name + page name:
String Url=httpcontext.current.request.url.absolutepath;
(or string url= HttpContext.Current.Request.Path;)
Url= aaa/bbb.aspx
"4" Gets the domain name:
String Url=httpcontext.current.request.url.host;
Url= www.test.com
"5" gets the parameter:
String Url= HttpContext.Current.Request.Url.Query;
Url=? Id=5&name=kelli
Reprint ASP. How to get the various parts of the request URL in net