zoukankan      html  css  js  c++  java
  • [置顶] 利用Global.asax的Application_BeginRequest 实现url 重写 无后缀

    利用Global.asax的Application_BeginRequest 实现url 重写 无后缀

    <%@ Application Language="C#" %>
    
    <script RunAt="server">
        void Application_BeginRequest(object sender, EventArgs e)
        {
            string oldUrl = System.Web.HttpContext.Current.Request.RawUrl; //获取初始url
    
            //~/123.aspx →  ~/Index.aspx?id=123
            Regex reg = new Regex(@"^/d+.html");
            if (reg.IsMatch(oldUrl))
            {
                string id = reg.Match(oldUrl).ToString().Substring(1, reg.Match(oldUrl).ToString().LastIndexOf(".") - 1);
                Context.RewritePath("~/Index.aspx?id=" + id);
            }
    
            //~/123 → ~/Index.aspx?id=123
            Regex reg1 = new Regex(@"^/d+$");
            if (reg1.IsMatch(oldUrl))
            {
                string id = reg1.Match(oldUrl).ToString().Substring(1);
                Context.RewritePath("~/Index.aspx?id=" + id);
            }
    
            //~/index/123 → ~/Index.aspx?id=123
            Regex reg3 = new Regex(@"^/index/d+$");
            if (reg3.IsMatch(oldUrl))
            {
                string id = reg3.Match(oldUrl).ToString().Substring(7);
                Context.RewritePath("~/Index.aspx?id=" + id);
            }
        }
           
    </script>
  • 相关阅读:
    第 6 章 存储
    第 6 章 存储
    第 6 章 存储
    第 6 章 存储
    第 6 章 存储
    vba:csv文件批量转换为xls的宏
    MySQL安装教程 推荐5.xx版本
    Cover Letter Draft for Application
    团队角色自测问卷答案
    联想Global future leader program面试
  • 原文地址:https://www.cnblogs.com/keanuyaoo/p/3257990.html
Copyright © 2011-2022 走看看