先添加引用URLRewriter.dll到项目下的bin目录中,下载:

https://files.cnblogs.com/tianguook/URLRewriter.rar

1.在web.config文件中  <configuration>节点的<configSections>下面的配置节点

<!--配置重写规则节点-->    

<section name="RewriterConfig" type="URLRewriter.Config.RewriterConfigSerializerSectionHandler, URLRewriter" />

2.在 <configuration>节点范围类编写重写规则

 <!--重写规则-->

<RewriterConfig>
    <Rules>
      <RewriterRule>
        <LookFor>~/index.html</LookFor>
        <SendTo>~/Default.aspx</SendTo>
      </RewriterRule>
      <RewriterRule>
        <LookFor>~/show_([0-9]*).html</LookFor>
        <SendTo>~/show.aspx?id=$1</SendTo>
      </RewriterRule>
      <RewriterRule>
        <LookFor>~/info/([0-9]*)/([0-9]*).html</LookFor>
        <SendTo>~/info.aspx?p1=$1&amp;p2=$2</SendTo>
      </RewriterRule>
    </Rules>
  </RewriterConfig>

3.在 <system.web>节点中的 <httpHandlers>下面配置

  <add verb="*" path="*.aspx" type="URLRewriter.RewriterFactoryHandler, URLRewriter" />  

 <add verb="*" path="*.html" type="URLRewriter.RewriterFactoryHandler, URLRewriter" /><!--不加此节点不能定向html页面-->

 4.在浏览器中输入 index.html,实际访问的是Default.aspx页面

    访问show_2.html实际是访问show.aspx?id=2的页面

  访问info/3/5.html实际是访问info.aspx?p1=3&p2=5的页面

 

测试项目下载:

https://files.cnblogs.com/tianguook/UrlRewrite.rar

posted on 2013-07-19 15:53  aparche  阅读(1206)  评论(0编辑  收藏  举报