博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ASP.NET中获取网站根目录和物理路径的方法
阅读量:7122 次
发布时间:2019-06-28

本文共 2024 字,大约阅读时间需要 6 分钟。

///         /// 取得网站的根目录的URL        ///         /// 
public static string GetRootURI() { string AppPath = ""; HttpContext HttpCurrent = HttpContext.Current; HttpRequest Req; if (HttpCurrent != null) { Req = HttpCurrent.Request; string UrlAuthority = Req.Url.GetLeftPart(UriPartial.Authority); if (Req.ApplicationPath == null || Req.ApplicationPath == "/") //直接安装在 Web 站点 AppPath = UrlAuthority; else //安装在虚拟子目录下 AppPath = UrlAuthority + Req.ApplicationPath; } return AppPath; } /// /// 取得网站的根目录的URL /// /// ///
public static string GetRootURI(HttpRequest Req) { string AppPath = ""; if(Req != null) { string UrlAuthority = Req.Url.GetLeftPart(UriPartial.Authority); if (Req.ApplicationPath == null || Req.ApplicationPath == "/") //直接安装在 Web 站点 AppPath = UrlAuthority; else //安装在虚拟子目录下 AppPath = UrlAuthority + Req.ApplicationPath; } return AppPath; } /// /// 取得网站根目录的物理路径 /// ///
public static string GetRootPath() { string AppPath = ""; HttpContext HttpCurrent = HttpContext.Current; if (HttpCurrent != null) { AppPath = HttpCurrent.Server.MapPath("~"); } else { AppPath = AppDomain.CurrentDomain.BaseDirectory; if (Regex.Match(AppPath, @"\\$", RegexOptions.Compiled).Success) AppPath = AppPath.Substring(0, AppPath.Length - 1); } return AppPath; }

 

转载于:https://www.cnblogs.com/wifi/articles/4661474.html

你可能感兴趣的文章
8.2. Pylons
查看>>
1040. Longest Symmetric String (25)
查看>>
全国主要城市不同日照标准的间距系数
查看>>
python网络爬虫(一):网络爬虫科普与URL含义
查看>>
工作了一个星期各位一定累了吧,那我们一起来表单验证一番吧!
查看>>
UVA 11732 - strcmp() Anyone?(Trie)
查看>>
java遍历hashMap、hashSet、Hashtable
查看>>
tcpdump
查看>>
如何注入值到Spring bean属性
查看>>
xm list源码分析
查看>>
PHPStorm 调式JS /同时调式PHP和jS
查看>>
JavaScript中的shift()、unshift()和pop()函数
查看>>
css案例学习之div与span的区别
查看>>
大话PHP缓存头
查看>>
【Java学习笔记之三十一】详解Java8 lambda表达式
查看>>
[zt]OpenCV2.1.0的安装
查看>>
Elasticsearch——Search的基本介绍
查看>>
Vue v-bind的使用
查看>>
第 22 章 Beta
查看>>
Linux 监视文件、文件夹改动
查看>>