获得当前网页的页面名称 list.aspx - GetCurPageName

2017-01-26 09:33:08  访问(1564) 赞(0) 踩(0)


        /// <summary>
        /// 获得当前网页的页面名称 list.aspx - GetCurPageName
        /// </summary>
        /// <returns></returns>
        public string GetCurPageName()
        {
            HttpContext hc = HttpContext.Current;

            if (hc == null)
            {

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

            // 虚拟目录加完整参数页面地址 //
            // /SlowXWebSite/Test/WebCommon/Default.aspx?id=default.aspx&web=%cb%aa%d2%b6&dt=D%3a%5ccanoe%5cs.aspx&p=fdf%5cf%2ffds.fdsf%3ffdf //
            string strPathAndQuery = hc.Request.Url.PathAndQuery;

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


            int idx = strPathAndQuery.LastIndexOf("?");


            if (idx != -1)
                strPathAndQuery = strPathAndQuery.Substring(0, idx);

            idx = strPathAndQuery.LastIndexOf("/");

            if (idx != -1)
                strPathAndQuery = strPathAndQuery.Substring(idx + 1);

            return strPathAndQuery;

        }


标签:获得当前网页的页面名称 list.aspx - GetCurPageName 

上一条:

下一条:


 

相关评论

评论加载中……
 

发表评论

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