Asp.net obtains the code of various attributes (file names, parameters, domain names, etc.) of the current url.

Source: Internet
Author: User

Set the full address of the current page to: http://www.jb51.net/aaa/bbb.aspx? Id = 5 & name = kelli
"Http: //" is the protocol name.
"Www.jb51.net" is a domain name
"Aaa" is the site name
"Bbb. aspx" is the page name (file name)
"Id = 5 & name = kelli" is a parameter
[1] obtain the complete url (protocol name + domain name + site name + file name + parameter)
Copy codeThe Code is as follows:
String url = Request. Url. ToString ();
Url = http://www.jb51.net/aaa/bbb.aspx? Id = 5 & name = kelli

[2] retrieve site name + Page name + parameters:
Copy codeThe Code is as follows:
String url = Request. RawUrl;
(Or string url = Request. Url. PathAndQuery ;)
Url =/aaa/bbb. aspx? Id = 5 & name = kelli

[3] retrieve site name + Page name:
Copy codeThe Code is as follows:
String url = HttpContext. Current. Request. Url. AbsolutePath;
(Or string url = HttpContext. Current. Request. Path ;)
Url = aaa/bbb. aspx

[4] retrieve domain names:
Copy codeThe Code is as follows:
String url = HttpContext. Current. Request. Url. Host;
Url = www.jb51.net

[5] GET parameters:
Copy codeThe Code is as follows:
String url = HttpContext. Current. Request. Url. Query;
Url =? Id = 5 & name = kelli


Copy codeThe Code is as follows:
Request. RawUrl: Get the URL Information of the client Request (excluding the host and port) ------>/Default2.aspx
Request. ApplicationPath: Obtain the virtual path of ASP. NET applications on the server. ------>/
Request. CurrentExecutionFilePath: Obtain the virtual path of the current Request. ------>/Default2.aspx
Request. Path: Obtain the virtual Path of the current Request. ------>/Default2.aspx
Request. PathInfo: obtain the additional path information of the resource with the URL extension ------>
Request. PhysicalPath: Obtain the physical file system path corresponding to the requested URL. ------> E: \ temp \ Default2.aspx
Request. Url. LocalPath: ------>/Default2.aspx
Request. Url. AbsoluteUri: ------ & gt; http: // localhost: 8080/Default2.aspx
Request. Url. AbsolutePath: ---------------------------->/Default2.aspx

Related Article

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.