The last time I saw a making sense of ASP. NET paths article about getting URL-related information in. net, I felt that the summary was very good, eliminating some of my fuzzy understandings. In the past, I used to look for the request documentation in msdn, but I am not clear about the differences between each attribute. Today I also want to sort out some common attributes and make a summary. If anything is wrong, please advise.
- Download the code in this article
Let's assume that we access this address: http: // localhost: 1351/website1/DIR/default. aspx/adsf? Id = 12 # test. The return values of each method are as follows.
ASP. NET |
Request Property |
Result |
Remark |
Request. applicationpath |
/Website1 |
The path relative to the root directory of the application (rather than the virtual directory) |
Request. physicalapplicationpath |
C: \ Documents ents and Settings \ wstone. spansion \ Desktop \ website1 \ |
Physical path of the application root directory |
Request. physicalpath |
C: \ Documents ents and Settings \ wstone. spansion \ Desktop \ website1 \ dir \ default. aspx |
Physical path of the current request |
Request. pathinfo |
/Adsf |
Additional path information |
Request. rawurl |
/Website1/DIR/default. aspx/adsf? Id = 12 |
Path of the current request to the application root directory |
Request. url |
Http: // localhost: 1351/website1/DIR/default. aspx/adsf? Id = 12 |
The complete path of the current request (excluding the path after) |
Request. currentexecutionfilepath |
/Website1/DIR/default. aspx |
Request. filepath |
/Website1/DIR/default. aspx |
Request. Path |
/Website1/DIR/default. aspx/adsf |
Request. servervariables ["SERVER_NAME"] |
Localhost |
Request. servervariables ["server_port"] |
1351 |
Request. servervariables ["server_port_secure"] |
0 |
Server. mappath ("~ ") |
C: \ Documents ents and Settings \ wstone. spansion \ Desktop \ website1 |
Server. mappath ("~ /") |
C: \ Documents ents and Settings \ wstone. spansion \ Desktop \ website1 \ |
Server. mappath ("~ /1.jpg ") |
C: \ Documents ents and Settings \ wstone. spansion \ Desktop \ website1 \ 1.jpg |
|
# Test |
In ASP. NET, the test after # is not obtained, because # The page is not sent back. |
PS: Open the website1 website in vs2005 and view it in the browser. website1 is a virtual directory.
Javascript |
Location Property |
Result |
Location. Hash |
# Test |
Location. Host |
Localhost: 1351 |
Location. hostname |
Localhost |
Location. href |
Http: // localhost: 1351/website1/DIR/default. aspx/adsf? Id = 12 # Test |
Location. pathname |
/Website1/DIR/default. aspx/adsf |
Location. Port |
1351 |
Location. Protocol |
HTTP: |
Location. Search |
? Id = 12 |