获得相关虚拟根目录

2014-08-03 10:51:23  访问(2485) 赞(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;
        }


标签:获得相关虚拟根目录    常用代码    web代码    asp.net代码    相对路径    PhyPath 

上一条:

下一条:


 

相关评论

评论加载中……
 

发表评论

类型:
内容:
  (Alt+Enter)