From: http://www.cnblogs.com/zyip/archive/2009/08/13/1544968.html
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 to see what information it contains. Foreach (string s in Request. ServerVariables)
{
Response. Write (s + ":" + Request. ServerVariables [s] + "<br/> ");
}
Path Conversion
1. convert to the Server path (Server. MapPath)
An interesting question about web server development and design is address translation. 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); output: 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.