用Intelligencia.UrlRewriter实现URL重写

 利用Open Source Intelligencia.UrlRewriter实现重写url
      实现效果如下:
  ~/video 到 ~/*.aspx(或者~/tags/*.aspx)
     ~/a.htm(或者自定义的扩展名) 到 ~/a.aspx
     ~/class/(.+)   到  ~/Class/Default.aspx?classid=$1
     等效果

    方法如下:
  (1)下载Intelligencia.UrlRewriter.dll文件
  (2)将Intelligencia.UrlRewriter.dll引用到你的website程序中
  (3)配置webconfig
     1)添加 Configuration section handler:
<configSections>
  <section
   name="rewriter"
   requirePermission="false"
   type="Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler, Intelligencia.UrlRewriter" />
 </configSections>


     2)添加 UrlRewriter mapper HttpModule:
<system.web>
  <httpModules>
   <add
    type="Intelligencia.UrlRewriter.RewriterHttpModule, Intelligencia.UrlRewriter"
    name="UrlRewriter" />
  </httpModules>
 </system.web>
    3)添加 重写规则到 web.config的configuration结点中,如下
<rewriter>
<rewrite url="/tags/(.+)" to="/tagcloud.aspx?tag=$1" /> 
 </rewriter>
整个web.config文件

 1 <? xml version="1.0" ?>
 2 < configuration >
 3      < configSections >
 4          < section
 5              name ="rewriter"
 6             requirePermission ="false"
 7             type ="Intelligencia.UrlRewriter.Configuration.RewriterConfigurationSectionHandler, Intelligencia.UrlRewriter"   />
 8      </ configSections >
 9      < appSettings />
10      < connectionStrings />
11      < system.web >
12          < httpModules >
13              < add
14                  type ="Intelligencia.UrlRewriter.RewriterHttpModule, Intelligencia.UrlRewriter"
15                 name ="UrlRewriter"   />
16          </ httpModules >
17
18     
19          < compilation  debug ="true" />
20         
21          < authentication  mode ="Windows" />
22
23      </ system.web >
24     
25      < rewriter >         
26          < rewrite  url ="~/tags/(.+)"  to ="~/tag/tagcloud.aspx?tag=$1"   />
27          < rewrite  url ="~/video"  to ="~/Class/Default.aspx"   />
28          < rewrite  url ="~/class/(.+)"  to ="~/Class/Default.aspx?classid=$1"   />
29
30          < rewrite  url ="~/test_([a-zA-Z]+).aspx$"  to ="~/Show.aspx?Code=$1"  processing ="stop"   />
31          < rewrite  url ="~/test_([a-zA-Z]+).html$"  to ="~/Show.aspx?Code=$1"  processing ="stop"   />
32      </ rewriter >
33     
34 </ configuration >
35

  (4)如果需要重写为htm、其它扩展名或者没有扩展名的url时,需要在IIS中设置
   设置方法如下:
        在windowXP系统中:
             1)Open Up IIS and Navigate to the “Home Directory Tab” 
               2)Select “Configuration” 
               3)Click “Add” and enter “C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll” in the Executable box. For the file extension, enter “.*”. Finally, make sure that “Check that file exists” is not checked. 
        在window 2003server中请参考:
        http://urlrewriter.net/index.php/support/installation/windows-server-2003/

        示例代码下载             


 

转载于:https://www.cnblogs.com/luyinghuai/archive/2008/05/01/1178687.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值