1. 程式人生 > >ASP.NET獲取路徑的方法

ASP.NET獲取路徑的方法

end cdir mappath 加載 sam main RR tex b站

HttpContext.Current.Request.PhysicalPath; // 獲得當前頁面的完整物理路徑.比如

F:\XFU.NSQS\project\website\Default.aspx
HttpContext.Current.Request.PhysicalApplicationPath; // 獲得當前程序運行的物理路徑比

如F:\XFU.NSQS\project\website\
HttpContext.Current.Server.MapPath(@"\"); 這個就是在頁面中的MapPath了.一樣用法

HttpRuntime.AppDomainAppPath //這個是新發現的,很好用.

還有一個是用來處理在asp.net中調用dll文件,而DLL文件如果想知道當前的web站點的工作目錄可

以用
System.AppDomain.CurrentDomain.BaseDirectory

網站在服務器磁盤上的物理路徑: HttpRuntime.AppDomainAppPath
虛擬程序路徑: HttpRuntime.AppDomainAppVirtualPath

HttpContext.Current.Request.ApplicationPath虛擬應用程序根路徑
HttpContext.Current.Server.MapPath(".")當前的絕對路徑
HttpContext.Current.Server.MapPath(HttpContext.Current.Request.ApplicationPath)系統的

根目錄

sb.Append(string.Format("當前請求的虛擬路徑: {0}",Server.HtmlEncode

(Request.CurrentExecutionFilePath)));
sb.Append(string.Format("獲取當前應用程序的根目錄路徑: {0}",

Server.HtmlEncode(Request.ApplicationPath)));
sb.Append(string.Format("當前請求的虛擬路徑: {0}",Server.HtmlEncode

(Request.FilePath)));
sb.Append(string.Format("當前請求的虛擬路徑: {0}",Server.HtmlEncode

(Request.Path)));
sb.Append(string.Format("獲取當前正在執行的應用程序的根目錄的物理文件系統路徑:

{0}", Server.HtmlEncode(Request.PhysicalApplicationPath)));
sb.Append(string.Format("獲取與請求的 URL 相對應的物理文件系統路徑: {0}",

Server.HtmlEncode(Request.PhysicalApplicationPath)));

當前請求的虛擬路徑: /aDirectory/Sample/responseHtml.aspx
獲取當前應用程序的根目錄路徑: /aDirectory
當前請求的虛擬路徑: /aDirectory/Sample/responseHtml.aspx
當前請求的虛擬路徑: /aDirectory/Sample/responseHtml.aspx
獲取當前正在執行的應用程序的根目錄的物理文件系統路徑: E:\Visual Studio 2005\
獲取與請求的 URL 相對應的物理文件系統路徑: E:\Visual Studio 2005\\aDirectory\

sb.Append(string.Format("獲取項目完整的絕對路徑: {0}",

System.AppDomain.CurrentDomain.BaseDirectory.ToString()));
//僅在嘗試向此域中加載程序集之後,此屬性才可用
sb.Append(string.Format("獲取項目,它由程序集沖突解決程序用來探測動態創建的

程序集: {0}", System.AppDomain.CurrentDomain.DynamicDirectory));
sb.Append(string.Format("獲取磁盤上指向應用程序目錄的物理路徑。: {0}",

System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath));
sb.Append(string.Format("獲取應用程序的虛擬根路徑: {0}",

System.Web.Hosting.HostingEnvironment.ApplicationVirtualPath));
sb.Append(string.Format("獲取站點的名稱。: {0}",

System.Web.Hosting.HostingEnvironment.SiteName));
//sb.Append(string.Format("獲取此應用程序的虛擬路徑提供程序。: {0}",

System.Web.Hosting.HostingEnvironment.VirtualPathProvider));
sb.Append(string.Format("返回與 Web 服務器上的指定虛擬路徑相對應的物理文件

路徑。: {0}", Server.MapPath("sss.aspx")));

ASP.NET獲取路徑的方法