Reprint ASP. How to get the various parts of the request URL in net

Source: Internet
Author: User

Reprint Original Address


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.Segments /

The following sections are reproduced in the Source: (

Assuming the current page full address is: Http://

"/HTTP" is the protocol name

"" 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://

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

String Url=request.rawurl;

(or string url=request.url.pathandquery;)


"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:



"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

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: 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.