UrlReWriter使用经验小结

UrlRewriter 是微软封装好了的一个URL重写组件。使用它可以让我节约很多自已开发的时间。

第一步,下载UrlRewriter.dll组件, copy到你的项目 bin 目录下。

第二步,在Web.config中加入:

 

  
    
1 < configuration >
2    < configSections >
3       < section name = " RewriterConfig " type = " URLRewriter.Config.RewriterConfigSerializerSectionHandler, URLRewriter " />
4    </ configSections >
5  

 

第三步,加入重写的规则节点:

 

代码
   
     
< RewriterConfig >
< Rules >
< RewriterRule >
< LookFor >~/ commlist / (\d + ).htm </ LookFor >
< SendTo >~/ commlist.aspx ? newsclass = $ 1 </ SendTo >
</ RewriterRule >
< RewriterRule >
< LookFor >~/ newslist / (\d + ).htm </ LookFor >
< SendTo >~/ newslist.aspx ? newsclass = $ 1 </ SendTo >
</ RewriterRule >
< RewriterRule >
< LookFor >~/ down / (\d + ) / (\d + ).htm </ LookFor >
< SendTo >~/ down.aspx ? id = $ 1 & amp;k = $ 2 </ SendTo >
</ RewriterRule >
< RewriterRule >
< LookFor >~/ down / (\d + ).htm </ LookFor >
< SendTo >~/ down.aspx ? id = $ 1 </ SendTo >
</ RewriterRule >
< RewriterRule >
< LookFor >~/ downtype / (\d + ).htm </ LookFor >
< SendTo >~/ downtype.aspx ? id = $ 1 </ SendTo >
</ RewriterRule >
< RewriterRule >
< LookFor >~/ downlist </ LookFor >
< SendTo >~/ downlist.aspx </ SendTo >
</ RewriterRule >
< RewriterRule >
< LookFor >~/ piclist / (\d + ).htm </ LookFor >
< SendTo >~/ piclist.aspx ? id = $ 1 </ SendTo >
</ RewriterRule >
< RewriterRule >
< LookFor >~/ newssearch / (\d + ) / ([\s\S] + ).htm </ LookFor >
< SendTo >~/ newssearch.aspx ? lx = $ 1 & amp;key = $ 2 </ SendTo >
</ RewriterRule >
< RewriterRule >
< LookFor >~/ newssearch / (\d + ).htm </ LookFor >
< SendTo >~/ newssearch.aspx ? lx = $ 1 </ SendTo >
</ RewriterRule >
< RewriterRule >
< LookFor >~/ newssearch / ([\s\S] + ).htm </ LookFor >
< SendTo >~/ newssearch.aspx ? key = $ 1 </ SendTo >
</ RewriterRule >
< RewriterRule >
< LookFor >~/ flvlist </ LookFor >
< SendTo >~/ flvlist.aspx </ SendTo >
</ RewriterRule >
< RewriterRule >
< LookFor >~/ flvclass / (\d + ).htm </ LookFor >
< SendTo >~/ flvclass.aspx ? cId = $ 1 </ SendTo >
</ RewriterRule >
</ Rules >
</ RewriterConfig >

 

第四步,加入模块配置(写在<system.web>里面):

 

  
    
< httpModules >
< add type = " URLRewriter.ModuleRewriter, URLRewriter " name = " ModuleRewriter " />
</ httpModules >

 

第五步,在模块配置中加入:

代码
   
     
< httpHandlers >
< remove verb = " * " path = " *.asmx " />
< add verb = " * " path = " *.asmx " validate = " false " type = " System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35 " />
< add verb = " * " path = " *_AppService.axd " validate = " false " type = " System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35 " />
< add verb = " GET,HEAD " path = " ScriptResource.axd " type = " System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35 " validate = " false " />
</ httpHandlers >

 

 

第六步,在IIS你的站点属性主目录配置映谢 加入一个和 aspx 页面的配置相同的扩展名项。注意“确认文件是否存在”不要勾选,否则会出现找不到文件。

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll

 

第七步:如果你的页面有回传。比如说放了DATAGRID,有分页的,你点到下一页就发现,晕倒,又出问题了。

  这下怎么办呢,这个其实微软件的网站上就有说到,我在这里简述一下了。

  第六步,加入窗体回传保持的组件:

  在原来你下载的项目里找到 ActionlessForm.dll 放到你的项目 bin 目录下。

  然后在你的这个页面中加入:

<%@ Register TagPrefix="skm" Namespace="ActionlessForm" Assembly="ActionlessForm" %>
再把你的<Form...>改为:
<skm:Form id="你的表单名" method="post" runat="server">
.....
</skm:Form>

  That's All.现在你可以高枕无忧了。一切如你所愿。

有问题还可参考:http://www.cnblogs.com/mouhong-lin/archive/2008/08/07/1262965.html

你可能感兴趣的:(urlrewrite)