Server.MapPath ()

Source: Internet
Author: User

1, Server.MapPath () Introduction

The Server.MapPath (string path) function returns 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.

The full name of Server.MapPath () is System.Web.HttpContext.Current.Server.MapPath (). Sometimes, when you debug a program, you will be prompted with "the name" Server "error does not exist in the current context, 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.

2. Server.MapPath () application

Server.MapPath (""): Returns the physical file path where the current page is located

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

Server.MapPath ("./"): Returns the physical file path where the current page is located

Server.MapPath (".. /"): Returns the physical file path at the top level of the current page

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

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

3, note: for Server.MapPath () specific return of what content, in different circumstances, the results may not be the same. As in the above six Server.MapPath () application, when I test in VS2010, the second item, the fourth item will prompt the error "failed to map the path", but when changing the location of the program, only the second item will prompt the error. So different software, different environment for its support is also different.

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.