asp.net 获取当前项目的根目录路径

获取网站根目录的方法有几种如:

Server.MapPath(Request.ServerVariables["PATH_INFO"])
   Server.MapPath("/")

   Server.MapPath("~/")//当前代码文件所在的目录路径
   Server.MapPath("")//当前代码文件所在的目录路径
   Server.MapPath(".")
   Server.MapPath("../")
   Server.MapPath("..") 

      Page.Request.ApplicationPath

 

System.Web.HttpContext.Current.Request.PhysicalApplicationPath

和Server.MapPath("~/")效果是一样的。

Server.MapPath("~/");//无论代码所在的文件的、页面路劲是什么,永远返回 C:\Inetpub\wwwroot\EnglishClub\(就是当前程序运行的所在根目录)

posted @ 2014-08-19 22:42  Young汨  阅读(1534)  评论(0编辑  收藏  举报