. Net-get the various parts of the current link (URL)-"reprint"

Source: Internet
Author: User
Tags httpcontext

The following is reproduced from: http://www.cnblogs.com/190196539/archive/2011/12/13/2286072.html

Set current page full address is: Http://www.jb51.net/aaa/bbb.aspx?id=5&name=kelli
"/HTTP" is the protocol name
"Www.jb51.net" 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)

The code is as follows:
String url=request.url.tostring ();
Url= Http://www.jb51.net/aaa/bbb.aspx?id=5&name=kelli


"2" gets the site name + page name + parameters:

The code is as follows:
String Url=request.rawurl;
(or string url=request.url.pathandquery;)
Url=/aaa/bbb.aspx?id=5&name=kelli


"3" Get Site name + page name:

The code is as follows:
String Url=httpcontext.current.request.url.absolutepath;
(or string url= HttpContext.Current.Request.Path;)
Url= aaa/bbb.aspx


"4" Gets the domain name:

The code is as follows:
String Url=httpcontext.current.request.url.host;
Url= www.jb51.net


"5" gets the parameter:

The code is as follows:
String Url= HttpContext.Current.Request.Url.Query;
Url=? Id=5&name=kelli



The code is as follows:
Request.rawurl: Gets the URL information for the client request (not including the host and port)------>/default2.aspx
Request.applicationpath: Gets the virtual path of an ASP. NET application on the server. ------>/
Request.currentexecutionfilepath: Gets the virtual path of the current request. ------>/default2.aspx
Request.path: Gets the virtual path of the current request. ------>/default2.aspx
Request.pathinfo: Take additional path information for a resource with a URL extension------>
Request.PhysicalPath: Gets the physical file system path that corresponds to the requested URL. ------>e:\temp\default2.aspx
Request.Url.LocalPath:------>/default2.aspx
Request.Url.AbsoluteUri:------>http://localhost:8080/default2.aspx
Request.Url.AbsolutePath:---------------------------->/default2.aspx

. Net-get the various parts of the current link (URL)-"reprint"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.