您的位置:首页 > 编程语言 > ASP

asp.net下返回文件路径,获得虚拟目录的网站的根目录

2009-03-17 10:47 369 查看
string Server.MapPath(string path)
返回与Web服务器上的指定虚拟路径相对应的物理文件路径。
Server.MapPath(Request.ServerVariables["PATH_INFO"])

 Server.MapPath("/")
 Server.MapPath("")
Server.MapPath(".")
 Server.MapPath("../")
 Server.MapPath("..")
Page.Request.ApplicationPath

以上的代码的运行结果如下:

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
由以上可以知道:
要想获得要是建立的虚拟目录的网站的根目录可以这样使用:
Server.MapPath(Page.Request.ApplicationPath)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: