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>
  • 相关阅读:
    青蛙学Linux—软件安装
    青蛙学Linux—文本编辑器Vi/Vim
    linux下安装java
    anaconda 换源
    origin从图中获得数据
    endnote X7参考文献缩进设置
    endnote X7 加入文献
    endnote X7使用方法
    linux下安装openmpi
    origin添加error bar
  • 原文地址:https://www.cnblogs.com/keanuyaoo/p/3257990.html
Copyright © 2011-2022 走看看