asp.net 文件路径之获得虚拟目录的网站的根目录
asp.net 文件路径之获得虚拟目录的网站的根目录
发布时间:2016-12-29 来源:查字典编辑
摘要:stringServer.MapPath(stringpath)返回与Web服务器上的指定虚拟路径相对应的物理文件路径。Server.Map...

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

(HttpContext.Current.Request.PhysicalApplicationPath);

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

运行结果:

C:InetpubwwwrootEnglishClubmanageWebForm1.aspx

C:Inetpubwwwroot

C:InetpubwwwrootEnglishClubmanage

C:InetpubwwwrootEnglishClubmanage

C:InetpubwwwrootEnglishClub

C:InetpubwwwrootEnglishClub

C:InetpubwwwrootEnglishClub

由以上可以知道:

要想获得要是建立的虚拟目录的网站的根目录可以这样使用:

Server.MapPath(Page.Request.ApplicationPath)

推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
相关阅读
网友关注
最新asp.net教程学习
热门asp.net教程学习
编程开发子分类