zoukankan      html  css  js  c++  java
  • URL的重写

    (简单)方法一:

    1.首先在网站的根目录下添加一个Global.asax,全局的应用程序
    2.找到Application_BeginRequest
          1)获取应用程序的路径将其变为相对路径
                 

    string url = Request.AppRelativeCurrentExecutionFilePath;

          2)用正则表达式匹配获得的路径
                  

    Match match = Regex.Match(url, @"~/BookList/BookList_(\d+).aspx");

           3)用Context.RewritePath跳转到对应的程序目录

    if (match.Success)
                {
                    string categoryId=match.Groups[1].Value;
                    Context.RewritePath("/BookList/BookList.aspx?categoryId=" + categoryId);
                }

    方法二:

    第一步:新建一个类,实现IHttpModule接口
    第二步:在Init的方法里边注册context.BeginRequest的事件
    第三步:写注册事件的context_BeginRequest的方法。

    void context_BeginRequest(object sender, EventArgs e)
            {
                HttpApplication app = sender as HttpApplication;
                string url = app.Request.RawUrl;//请求的路径
                Regex regex = new Regex(@"index\-(\d+)\.html");
                Match match = regex.Match(url);
                if (match.Success)
                {
                    int id = int.Parse(match.Groups[1].Value);
                    app.Context.RewritePath("Index.aspx?id="+id);
                }
            }

    第四步:在Web.config里边配置。

    <system.web>
          <httpModules>
            <add name="urlrewrite" type="WebUrlRewrite.UrlRewrite"/>//命名控件加类名
          </httpModules>
    <system.web>
  • 相关阅读:
    centos7安装kafka
    Qt——透明无边框Widget的bug
    Qt——浅谈样式表
    Qt——QLineEdit使用总结
    Qt——信号槽连接:基于字符串与基于函数的连接之间的不同
    Qt——树的搜索实现源码
    Qt——树结点的搜索
    Qt——鼠标拖动调整窗口大小
    Qt——右键菜单
    Qt——正则表达式
  • 原文地址:https://www.cnblogs.com/shinelhui/p/2889588.html
Copyright © 2011-2022 走看看