获得PhyPath

2015-12-05 09:26:52  访问(1494) 赞(0) 踩(0)

/// <summary>
        /// 如果是网站目录,返回"";如果是虚拟目录(Web),返回 /Web。则图片地址可以写成 GetPhyPath()+"/images/slowx.png"
        /// </summary>
        /// <returns></returns>
        public static string GetPhyPath()
        {
            HttpContext hc = HttpContext.Current;

            if (hc == null)
                throw new Exception("方法:" + MethodBase.GetCurrentMethod().ReflectedType.FullName + " " + MethodBase.GetCurrentMethod().ToString() + " 发生异常:" + "HttpContext hc = HttpContext.Current 为null");

            if (hc.Request.ApplicationPath == "/")
                return "";

            return hc.Request.ApplicationPath;
        }

        /// <summary>
        /// 获得 /Web
        /// </summary>
        /// <param name="hc"></param>
        /// <returns></returns>
        public static string GetPhyPath(HttpContext hc)
        {
             if (hc.Request.ApplicationPath == "/")
                return "";

            return hc.Request.ApplicationPath;
        }


标签:获得PhyPath 

上一条:

下一条:


 

相关评论

评论加载中……
 

发表评论

类型:
内容:
  (Alt+Enter)
 
  ┈全部┈  
 
(显示默认分类)