Use of Server.MapPath in ASP.

Source: Internet
Author: User

Http://www.studyofnet.com/news/184.html This article: The full name of Server.MapPath () is System.Web.HttpContext.Current.Server.MapPath ( )。 The function is to return the physical file path corresponding to the specified virtual path on the Web server. The parameter path is the virtual path of the Web server, and the return result is the physical file path corresponding to path. However, sometimes the parameter is not a virtual path, but rather a user-defined file name.

Server.MapPath Method effect

The MapPath method is used to return the physical file path that corresponds to the specified virtual path on the Web server.

Grammar
Server.MapPath (path);

Parameters
Path represents the virtual path on the Web server, and if the path value is NULL, the method returns the full physical path that contains the current application.

Precautions

Server.MapPath () sometimes prompts for the "Server" error in the current context when the program is debugging , which does not support the use of function Server.MapPath (). Although the namespace "using System.Web;" is referenced. is useless, you need to use its full name, or the class that currently uses the Server.MapPath () function inherits from System.Web.UI.Page.

Server.MapPath () application

Assume that the current site directory for the E:\wwwroot application virtual directory for E:\wwwroot\company browses the page path to an ASPX page below E:\wwwroot\company\news\.

In this page, use the

Server.MapPath (""): Returns the physical file path where the current page is located: E:\wwwroot\company\news

Server.MapPath ("/"): Returns the physical file path where the application root is located: E:\wwwroot

Server.MapPath ("./"): Returns the physical file path where the current page is located: E:\wwwroot\company\news

Server.MapPath (".. /"): Returns the physical file path on the previous level where the current page is located: E:\wwwroot\company

Server.MapPath ("~/"): Returns the application's virtual directory (path): E:\wwwroot\company

Server.MapPath ("~"): Returns the application's virtual directory (path): E:\wwwroot\company

Asp. NET Server.MapPath () and Request.mappath () Use the difference:

Server.MapPath (String): is the file (or directory) relative to the current calling file is mapped to a physical path;


Request.mappath (String): is a string virtual path mapped to a physical path (no request for this method in ASP)

String in Server.MapPath (string) can use the ".. /"to refer to the parent directory, or even to skip the directory to the entire Web directory, such as: C:\WWWROOT
The directory is the Web root and is called in the root directory file for this server.mappath (".. /script File "), you can call scripts, resources, and so on outside the web directory.

The string in Request.mappath (string) is a virtual directory that is only relative to the Web virtual directory and does not allow ". /"mode call, can only be"/","/xx "and other strings

Use of Server.MapPath in ASP.

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.