zoukankan      html  css  js  c++  java
  • 【url重写】

    一、原理
    void Application_BeginRequest(object sender, EventArgs e)
        {
      //url重写
            HttpApplication app = sender as HttpApplication;
            string url = app.Request.RawUrl;
            Regex r = new Regex("/(\d+)/details\.htm",RegexOptions.IgnoreCase);
            Match m = r.Match(url);
            if (m.Success)
            {
                string id = m.Groups[1].Value;
                app.Context.RewritePath("~/PhotoDetails.aspx?id=" + id);
            }
        }

     二、urlRewriter
    1、在<configSections>节点加入
     <section name="RewriterConfig" type="URLRewriter.Config.RewriterConfigSerializerSectionHandler, URLRewriter" />
    2、在</configSections>之后加入
     
      <RewriterConfig>
        <Rules>
          <RewriterRule>
            <LookFor>~/(d{4})/(d{2})/Default.aspx</LookFor>
            <SendTo>~/Default.aspx?ID=$1</SendTo>
          </RewriterRule>
        </Rules>
      </RewriterConfig>
    3、<httpHandlers>中加入
    <add verb="*" path="*.aspx" type="URLRewriter.RewriterFactoryHandler, URLRewriter" />
    或者 <httpModules>加入
    <add type="URLRewriter.ModuleRewriter, URLRewriter" name="ModuleRewriter" />

    备注:关于url组件可在文件中下载

  • 相关阅读:
    第五周的学习进度情况
    周末经历之小体会
    构建之法阅读笔记5
    第四周的学习进度情况
    hashMap中如何形成循环链表的?
    代理模式
    sharing-jdbc实现读写分离及分库分表
    分库分表
    读写分离实现方式
    MySQL主从复制
  • 原文地址:https://www.cnblogs.com/baiboy/p/3150726.html
Copyright © 2011-2022 走看看