服务器之家:专注于服务器技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|JAVA教程|ASP教程|

服务器之家 - 编程语言 - ASP.NET教程 - asp.net 文件路径之获得虚拟目录的网站的根目录

asp.net 文件路径之获得虚拟目录的网站的根目录

2019-10-08 09:53asp.net教程网 ASP.NET教程

asp.net下获取文件路径常用代码,获得虚拟目录的网站的根目录

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:\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 

  C:\Inetpub\wwwroot\EnglishClub\ 
由以上可以知道: 
要想获得要是建立的虚拟目录的网站的根目录可以这样使用: 
Server.MapPath(Page.Request.ApplicationPath)

延伸 · 阅读

精彩推荐