UrlRewriter.net简单例子

 UrlRewriter.net的使用方法
    1,将Intelligencia.UrlRewriter.dll这个文件放到项目的bin目录下,然后添加对它的引用
    2,打开web.config这个文件,添加如下配置
        2.1 添加handler配置:
       <configSections>
  <section
   name="rewriter"
   type="Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler, Intelligencia.UrlRewriter" />
 </configSections>
     2.2 添加modul配置
     <system.web>
  <httpModules>
   <add
    type="Intelligencia.UrlRewriter.RewriterHttpModule, Intelligencia.UrlRewriter"
    name="UrlRewriter" />
  </httpModules>
 </system.web>
 
 
 3,添加你要重写的url规则:
     <rewriter>  
         --用正则表达式匹配url路径,然后跳到你想要的真实路径
            <rewrite url="^/admin/user/(\w{6,12})$" to="/admin/UserManager.aspx?UserName=$1" />--用户名只能是6到12位的字符
            <rewrite url="^/admin/product/(\d.+)$" to="/admin/ProductManager.aspx?Id=$1" />   --产品id只能是数字
        </rewriter>
       
    4,测试:

  在附件可以下载我的例子
        输入:http://localhost:6642/admin/user/linzhenchong成功
        输入:http://localhost:6642/admin/user/lzc失败

附件:/Files/Allnen/UrlRewriterTest_2009-11-8.7z

原文地址:https://www.cnblogs.com/seerlin/p/1598694.html