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

作者:互联网   出处:控件中国网   2014-11-05 19:05:38   阅读:1

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)

 

Copyright© 2006-2015 ComponentCN.com all rights reserved.重庆磐岩科技有限公司(控件中国网) 版权所有 渝ICP备12000264号 法律顾问:元炳律师事务所
客服软件
live chat