Sever.mappath()用法简介:

转自: 亿万年的探索,我就在这里...

server.mappath用法
 

./当前目录
/根目录
../上层目录(相对当前来说)

如果当前的网站目录为D:/wwwroot     浏览的页面路径为D:/wwwroot/company/news/show.asp
在show.asp页面中使用
Server.MapPath("./")    返回路径为:D:/wwwroot/company/news
Server.MapPath("/")     返回路径为:D:/wwwroot
Server.MapPath("../")    返回路径为:D:/wwwroot/company
server.MapPath(request.ServerVariables("Path_Info"))
Request.ServerVariables("Path_Translated")  
上面两种方式返回路径为 D:/wwwroot/company/news/show.asp

2   string Server.MapPath(string path)
返回与Web服务器上的指定虚拟路径相对应的物理文件路径。

<%=Server.MapPath(Request.ServerVariables["PATH_INFO"])%>

<%= Server.MapPath("/")%>
<%= Server.MapPath("")%>
<%=Server.MapPath(".")%>

<%= Server.MapPath("../")%>
<%= Server.MapPath("..")%>

以上的代码在http://localhost/EnglishClub/manage/WebForm1.aspx页面
运行结果:

C:/Inetpub/wwwroot/EnglishClub/manage/WebForm1.aspx

C:/Inetpub/wwwroot/
C:/Inetpub/wwwroot/EnglishClub/manage
C:/Inetpub/wwwroot/EnglishClub/manage

C:/Inetpub/wwwroot/EnglishClub/
C:/Inetpub/wwwroot/EnglishClub

 

3.Server.MapPath("~/")表示当前应用级程序的目录,如果是根目录,就是根目录,如果是虚拟目录,

     就是虚拟目录所在的位置 如:C:/Inetpub/wwwroot/Example/
     注:等效于Server.MapPath("~")。

 

你可能感兴趣的:(c,String,Path,web服务)