获得当前页面所在根目录地址

2015-12-05 09:29:09  访问(1373) 赞(0) 踩(0)


        /// <summary>
        /// 获得 当前页面所在根目录地址 ~ /Test/WebCommon/Default.aspx
        /// </summary>
        /// <returns></returns>
        public static string GetPagePath()
        {
            HttpContext hc = HttpContext.Current;

            if (hc == null)
            {

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


            string strOne = hc.Request.Url.LocalPath;
            string strTwo = GetPhyPath(hc);

            if (strOne == null || strOne.Length == 0)
                return "";

            if (strTwo == null || strTwo.Length == 0)
                return strOne;

            return strOne.Substring((strTwo).Length);
        }


标签:获得当前页面所在根目录地址 

上一条:

下一条:


 

相关评论

评论加载中……
 

发表评论

类型:
内容:
  (Alt+Enter)