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.