Server. MapPath and Request. MapPath () Usage

Source: Internet
Author: User
Tags servervariables
Server. MapPath and Request. MapPath () usage./Current Directory

/Root directory

../Upper-level directory (relative to the current one)

If the current website directory is D: \ wwwroot, the page path is D: \ wwwroot \ company \ news \ show. asp

Use

Server. MapPath ("./") Return Path: D: \ wwwroot \ company \ news

Server. MapPath ("/") Return Path: D: \ wwwroot

Server. MapPath ("../") Return Path: D: \ wwwroot \ company

Server. MapPath (request. ServerVariables ("Path_Info "))

Request. ServerVariables ("Path_Translated ")

The preceding two methods return the path D: \ wwwroot \ company \ news \ show. asp.



Differences between Server. MapPath () and Request. MapPath () in ASP. NET:

Server. MapPath (string): maps the files (or directories) of the currently called files to physical paths;

Request. MapPath (string): ing the string virtual path to the physical path (Request does not have this method in asp)

In server. mappath (string), the string can reference the parent directory in the "../" mode, or even jump this directory out of the entire web directory, such as: C: \ wwwroot

The directory is the web root directory. You can call this server. mappath ("../xyz.gif") in the root directory file to call scripts and resources outside the web directory.

Request. the string in mappath (string) is a virtual directory, which can only be in the form of a Web virtual directory and cannot be ".. /"method call, can only be"/","/xx "and other strings

Sometimes it is difficult to directly use server. mappath (string) to call a file, because different directories call the same server. mappath (string) function to obtain different values,

In special cases, you must determine the directory level to obtain the correct address. You can call the same directory file by using request. mappath (string. No directory judgment required

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.