Asp. NET Get URL Method Summary _ Practical Tips

Source: Internet
Author: User

Get full URL (protocol name + domain + site name + filename + parameter)

String fullurl = Request.Url.ToString ();

Gets the URL information requested by the client (excluding hosts and ports)

string rawurl = Request.rawurl;

Get Site name + page name

string absolutepath = Request.Url.AbsolutePath;

Get host part

string urlhost = Request.Url.Host;

Get the Parameters section

string urlquery = Request.Url.Query;

To get the virtual path to the ASP.net application on the server

string applicationpath = Request.applicationpath;

Gets the virtual path of the current request

string currentexecutionfilepath = Request.currentexecutionfilepath;

Gets the virtual path of the current request

string Path = Request.path;

Get additional path information for a resource with a URL extension

string pathinfo = Request.pathinfo;

Gets the physical file system path that corresponds to the requested URL

string physicalpath = Request.PhysicalPath;

Gets the local operating system representation of the file name

string localpath = Request.Url.LocalPath;

Get absolute URL

string Absoluteuri = Request.Url.AbsoluteUri;

Complete code Demo

Copy Code code as follows:

StringBuilder sb = new StringBuilder ();
Sb. Append ("Get the complete URL (protocol name + domain name + site names + filename + parameter):" + fullurl + "<br/>");
Sb. Append ("Get the URL information requested by the client (excluding host and port):" + Rawurl + "<br/>");
Sb. Append ("Get the Site name + page name:" + Absolutepath + "<br/>");
Sb. Append ("Get host part:" + urlhost + "<br/>");
Sb. Append ("Get parameter part:" + urlquery + "<br/>");
Sb. Append ("Get the application's virtual application root path:" + Applicationpath + "<br/>");
Sb. Append ("Get the virtual path of the current request:" + path + "<br/>");
Sb. Append ("Get additional path information for a resource with a URL extension:" + pathinfo + "<br/>");
Sb. Append ("Get the physical file system path corresponding to the requested URL:" + physicalpath + "<br/>");
Sb. Append ("Obtain the local operating system representation of the filename:" + localpath + "<br/>");
Sb. Append ("Get absolute URL:" + Absoluteuri + "<br/>");
Response.Write (sb.) ToString ());

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.