zoukankan      html  css  js  c++  java
  • asp.net中获取网站根目录和物理路径的方法

     /// <summary>
            /// 取得网站的根目录的URL
            /// </summary>
            /// <returns></returns>
            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;
            }
            /// <summary>
            /// 取得网站的根目录的URL
            /// </summary>
            /// <param name="Req"></param>
            /// <returns></returns>
            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;
            }
            /// <summary>
            /// 取得网站根目录的物理路径
            /// </summary>
            /// <returns></returns>
            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;
            }
  • 相关阅读:
    如何在工作组设置中将本地策略应用于 Windows Server 2000 上除管理员以外的所有用户
    中小规模NT网的安全策略(一)
    Windows 2000 中的域安全性策略
    HOW TO:在 Windows 2000 的“安全模板”管理单元中定义安全模板
    Windows 2000 安全配置工具
    组策略特性集的渐进指南
    域级别策略
    Windows命令
    winForm base64编码转换 上传文件到web服务器
    php定界符方便好用
  • 原文地址:https://www.cnblogs.com/kevinGao/p/2323339.html
Copyright © 2011-2022 走看看