Obtain URL Information in ASP. NET and JavaScript

Source: Internet
Author: User
Tags servervariables

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