ASP.NET获取路径的方法
HttpContext.Current.Request.PhysicalPath;??? // 獲得當(dāng)前頁面的完整物理路徑.比如
F:\XFU.NSQS\project\website\Default.aspx
HttpContext.Current.Request.PhysicalApplicationPath;?// 獲得當(dāng)前程序運行的物理路徑比
如F:\XFU.NSQS\project\website\
HttpContext.Current.Server.MapPath(@"\"); 這個就是在頁面中的MapPath了.一樣用法
HttpRuntime.AppDomainAppPath //這個是新發(fā)現(xiàn)的,很好用.
還有一個是用來處理在asp.net中調(diào)用dll文件,而DLL文件如果想知道當(dāng)前的web站點的工作目錄可
以用
System.AppDomain.CurrentDomain.BaseDirectory
網(wǎng)站在服務(wù)器磁盤上的物理路徑: HttpRuntime.AppDomainAppPath
虛擬程序路徑: HttpRuntime.AppDomainAppVirtualPath
HttpContext.Current.Request.ApplicationPath虛擬應(yīng)用程序根路徑?
HttpContext.Current.Server.MapPath(".")當(dāng)前的絕對路徑?
HttpContext.Current.Server.MapPath(HttpContext.Current.Request.ApplicationPath)系統(tǒng)的
根目錄
??????? sb.Append(string.Format("當(dāng)前請求的虛擬路徑: {0}",Server.HtmlEncode
(Request.CurrentExecutionFilePath)));
??????? sb.Append(string.Format("獲取當(dāng)前應(yīng)用程序的根目錄路徑: {0}",
Server.HtmlEncode(Request.ApplicationPath)));
??????? sb.Append(string.Format("當(dāng)前請求的虛擬路徑: {0}",Server.HtmlEncode
(Request.FilePath)));
??????? sb.Append(string.Format("當(dāng)前請求的虛擬路徑: {0}",Server.HtmlEncode
(Request.Path)));
??????? sb.Append(string.Format("獲取當(dāng)前正在執(zhí)行的應(yīng)用程序的根目錄的物理文件系統(tǒng)路徑:
{0}", Server.HtmlEncode(Request.PhysicalApplicationPath)));
??????? sb.Append(string.Format("獲取與請求的 URL 相對應(yīng)的物理文件系統(tǒng)路徑: {0}",
Server.HtmlEncode(Request.PhysicalApplicationPath)));
當(dāng)前請求的虛擬路徑: /aDirectory/Sample/responseHtml.aspx
獲取當(dāng)前應(yīng)用程序的根目錄路徑: /aDirectory
當(dāng)前請求的虛擬路徑: /aDirectory/Sample/responseHtml.aspx
當(dāng)前請求的虛擬路徑: /aDirectory/Sample/responseHtml.aspx
獲取當(dāng)前正在執(zhí)行的應(yīng)用程序的根目錄的物理文件系統(tǒng)路徑: E:\Visual Studio 2005\
獲取與請求的 URL 相對應(yīng)的物理文件系統(tǒng)路徑: E:\Visual Studio 2005\\aDirectory\
?
???????????? sb.Append(string.Format("獲取項目完整的絕對路徑: {0}",
System.AppDomain.CurrentDomain.BaseDirectory.ToString()));
??????????? //僅在嘗試向此域中加載程序集之后,此屬性才可用
??????????? sb.Append(string.Format("獲取項目,它由程序集沖突解決程序用來探測動態(tài)創(chuàng)建的
程序集: {0}", System.AppDomain.CurrentDomain.DynamicDirectory));
??????????? sb.Append(string.Format("獲取磁盤上指向應(yīng)用程序目錄的物理路徑。: {0}",
System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath));
??????????? sb.Append(string.Format("獲取應(yīng)用程序的虛擬根路徑: {0}",
System.Web.Hosting.HostingEnvironment.ApplicationVirtualPath));
??????????? sb.Append(string.Format("獲取站點的名稱。: {0}",
System.Web.Hosting.HostingEnvironment.SiteName));
??????????? //sb.Append(string.Format("獲取此應(yīng)用程序的虛擬路徑提供程序。: {0}",
System.Web.Hosting.HostingEnvironment.VirtualPathProvider));
??????????? sb.Append(string.Format("返回與 Web 服務(wù)器上的指定虛擬路徑相對應(yīng)的物理文件
路徑。: {0}", Server.MapPath("sss.aspx")));
?
轉(zhuǎn)載于:https://www.cnblogs.com/KingsLiu/p/9013067.html
總結(jié)
以上是生活随笔為你收集整理的ASP.NET获取路径的方法的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: PGIS大数据量点位显示方案
- 下一篇: asp.net ajax控件工具集 Au