任何人都可以解释 Server.MapPath(。), Server.MapPath(〜), Server.MapPath(@\)和 Server.MapPath(/)?
Can anyone explain the difference between Server.MapPath("."), Server.MapPath("~"), Server.MapPath(@"\") and Server.MapPath("/")?
推荐答案Server.MapPath 指定将映射到物理目录。
- Server.MapPath(。) 1 返回正在执行的文件的当前物理目录(例如aspx)
- Server.MapPath(..)返回父目录
- Server.MapPath(〜)返回应用程序根目录的物理路径
- Server.MapPath(/)返回到根域的物理路径(不一定与根的应用程序)
- Server.MapPath(".")1 returns the current physical directory of the file (e.g. aspx) being executed
- Server.MapPath("..") returns the parent directory
- Server.MapPath("~") returns the physical path to the root of the application
- Server.MapPath("/") returns the physical path to the root of the domain name (is not necessarily the same as the root of the application)
一个例子:
假设你指向一个网站应用程序( http://www.exampl e / )to
Let's say you pointed a web site application (www.example/) to
C:\Inetpub\wwwroot并将您的商店应用程序(IIS中的虚拟目录作为应用程序标记为IIS)安装在
and installed your shop application (sub web as virtual directory in IIS, marked as application) in
D:\WebApps\shop例如,如果在以下请求中调用 Server.MapPath():
For example, if you call Server.MapPath() in following request:
www.example/shop/products/GetProduct.aspx?id=2342然后:
- Server.MapPath(。) 1 返回 D:\WebApps\shop\products
- Server.MapPath(..)返回 D:\WebApps\shop
- Server.MapPath(〜)返回 D:\WebApps\shop
- Server.MapPath(/)返回 C:\Inetpub\wwwroot
- Server.MapPath(/ shop)返回 D:\WebAp ps \shop
- Server.MapPath(".")1 returns D:\WebApps\shop\products
- Server.MapPath("..") returns D:\WebApps\shop
- Server.MapPath("~") returns D:\WebApps\shop
- Server.MapPath("/") returns C:\Inetpub\wwwroot
- Server.MapPath("/shop") returns D:\WebApps\shop
如果Path以正斜杠( / )或反斜杠( \ ), MapPath()返回路径为如果Path是一个完整的虚拟路径。
If Path starts with either a forward slash (/) or backward slash (\), the MapPath() returns a path as if Path was a full, virtual path.
如果路径不以斜线开头,则 MapPath()返回相对于请求正在处理。
If Path doesn't start with a slash, the MapPath() returns a path relative to the directory of the request being processed.
注意:在C#中, @ 是逐字字母字符串运算符,意思是字符串应该按原样使用,不能用于转义序列。
Note: in C#, @ is the verbatim literal string operator meaning that the string should be used "as is" and not be processed for escape sequences.
脚注
更多推荐
Server.MapPath(“。”),Server.MapPath(“〜”),Server.MapPath(@“\”),Server.MapPath(“/”
发布评论