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>
  • 相关阅读:
    Construction构造函数
    映射验证
    映射设置
    条件映射
    映射前和映射后的操作
    AutoMapper 5.0-升级指南
    Bootstrap Tree View
    MiniProfiler使用笔记
    关于添加数据自定义编号格式问题
    【Postgresql】数据库函数
  • 原文地址:https://www.cnblogs.com/keanuyaoo/p/3257990.html
Copyright © 2011-2022 走看看