Path memorandum in Asp.net

Source: Internet
Author: User
Tags comparison table servervariables
In Web server development, different forms of paths are often encountered, and it is often hard to remember how to obtain a specific format, today, I took some time to make a simple comparison table between the commonly used path obtaining methods and formats for future reference.
Request Information
Request. apprelativecurrentexecutionfilepath ~ /Sysoption/billingsetup1.aspx
Request. applicationpath/
Request. currentexecutionfilepath/sysoption/billingsetup1.aspx
Request. filepath/sysoption/billingsetup1.aspx
Request. Path/sysoption/billingsetup1.aspx
No request. pathinfo (other usage to be tested)
Request. physicalapplicationpath D: \ vssworkfolder \ briish_school_mis \ SRC \ website \
Request. physicalpath D: \ vssworkfolder \ briish_school_mis \ SRC \ website \ sysoption \ billingsetup1.aspx
Request. userhostaddress 192.168.1.6
Request. userhostname 192.168.1.6
Request. url. tostring () http: // 192.168.1.6/sysoption/billingsetup1.aspx? X = d
Request. urlreferrer: Empty reference or jump to the Source Page address

Related information obtained from the request. servervariables collection:
The left column is the server variable name, the right column is the value, and the value is obtained through request. servervariables [server variable name ].
Appl_md_path:/lm/w3svc/894523/root
Appl_physical_path: D: \ vssworkfolder \ briish_school_mis \ SRC \ website \
Instance_meta_path:/lm/w3svc/894523
Local_addr: 192.168.1.6
Path_info:/sysoption/billingsetup1.aspx
Path_translated: D: \ vssworkfolder \ briish_school_mis \ SRC \ website \ sysoption \ billingsetup1.aspx
Remote_addr: 192.168.1.6
Remote_host: 192.168.1.6
Script_name:/sysoption/billingsetup1.aspx
SERVER_NAME: 192.168.1.6
URL:/sysoption/billingsetup1.aspx

Request. servervariables is a powerful tool that can help us get a lot of client and web host information. If you are interested, you can use the following Code See what information it actually contains. Foreach ( String S In Request. servervariables)
{
Response. Write (S +   " : "   + Request. servervariables [s] +   " <Br/> " );
}

path conversion
1. converting to a server path (server. mappath)
an interesting problem in Web server development design is address conversion. For example, HTTP address/images/a.txt. If you want to read the file through Io on the server side, you must have the local address of the file (such as C: \ windows \ system32 \ xx. DLL) ", then server. mappath is useful
response. write (request. mappath (request. path); the output is D: \ vssworkfolder \ briish_school_mis \ SRC \ website \ sysoption \ billingsetup1.aspx
2. convert to HTTP address (page. resolveclienturl page. resolveurl)
response. write (page. resolveclienturl ("~ /A/a.jpg "); the output is ../A/a.jpg
response. Write (page. resolveurl ("~ /A/a.jpg "); the output is/A/a.jpg

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.