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