使用Server.Mappath(QUOT;&QUOT),使用Server.Mappath(QUOT;〜&QUOT),使用Server.Mappath(@" \\&QUOT),使用Server.Mappath(QUOT; /&QUOT)。有什么不同? [英] Server.MapPath("."), Server.MapPath("~"), Server.MapPath(@"\"), Server.MapPath("/"). What is the difference?
问题描述
谁能解释(。),使用Server.Mappath
使用Server.Mappath之间的差值(〜)
,使用Server.Mappath(@\\)
和使用Server.Mappath(/)
?
推荐答案
使用Server.Mappath 指定的相对或虚拟路径映射以物理目录
Server.MapPath specifies the relative or virtual path to map to a physical directory.
-
使用Server.Mappath(。)
1 返回正在执行的文件的当前物理目录(如C ++) -
使用Server.Mappath(..)
返回上一级目录 -
使用Server.Mappath(〜)
返回给应用程序 的根的物理路径 -
使用Server.Mappath(/)
返回到域名的根目录的物理路径(不一定是相同的应用程序的根目录)
Server.MapPath(".")
1 returns the current physical directory of the file (e.g. aspx) being executedServer.MapPath("..")
returns the parent directoryServer.MapPath("~")
returns the physical path to the root of the applicationServer.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.example.com/ ),以
Let's say you pointed a web site application (http://www.example.com/) to
C:\Inetpub\wwwroot
和
D:\WebApps\shop
例如,如果你调用中使用Server.Mappath以下要求:
For example, if you call Server.MapPath in following request:
http://www.example.com/shop/products/GetProduct.aspx?id=2342
然后
-
使用Server.Mappath(。)
1 收益D:\\ WebApps的\\店\\产品
-
使用Server.Mappath(..)
收益D:\\ WebApps的\\店
-
使用Server.Mappath(〜)
收益D:\\ WebApps的\\店
-
使用Server.Mappath(/)
收益C:\\的Inetpub \\ wwwroot文件
-
使用Server.Mappath(/店)
收益D:\\ WebApps的\\店
Server.MapPath(".")
1 returnsD:\WebApps\shop\products
Server.MapPath("..")
returnsD:\WebApps\shop
Server.MapPath("~")
returnsD:\WebApps\shop
Server.MapPath("/")
returnsC:\Inetpub\wwwroot
Server.MapPath("/shop")
returnsD:\WebApps\shop
如果路径的开头或者是向前( /
)或反斜杠( \\
),MapPath方法返回仿佛是路径一个完整的虚拟路径的路径。
If Path starts with either a forward (/
) or backward slash (\
), the MapPath method returns a path as if Path were a full, virtual path.
如果路径不以斜线开始,则MapPath方法返回相对于正在处理的请求的目录的路径。
If Path doesn't start with a slash, the MapPath method returns a path relative to the directory of the request being processed.
的注意:在C#,@是逐字字符串字面意思运营该字符串应该用原样和转义序列不会被处理的
的脚注的
-
使用Server.Mappath(空)
和使用Server.Mappath()
会的产生这种效果太 。
Server.MapPath(null)
andServer.MapPath("")
will produce this effect too.
这篇关于使用Server.Mappath(QUOT;&QUOT),使用Server.Mappath(QUOT;〜&QUOT),使用Server.Mappath(@" \\&QUOT),使用Server.Mappath(QUOT; /&QUOT)。有什么不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!