ASP.NET 如何实现伪静态

其实所谓的伪静态页面,就是指的URL重写.

1.首先在web.config里写

view plaincopy to clipboardprint?
<configSections>  
    <section name="RewriterConfig" type="URLRewriter.Config.RewriterConfigSerializerSectionHandler, URLRewriter"/>  
  </configSections>  
<configSections>
    <section name="RewriterConfig" type="URLRewriter.Config.RewriterConfigSerializerSectionHandler, URLRewriter"/>
  </configSections>
 

2.在web.config里添加以下节点

view plaincopy to clipboardprint?
<httpHandlers>  
      <add verb="*" path="*.aspx" type="URLRewriter.RewriterFactoryHandler, URLRewriter" />  
      <add verb="*" path="*.html" type="URLRewriter.RewriterFactoryHandler, URLRewriter" />  
    </httpHandlers>  
<httpHandlers>
      <add verb="*" path="*.aspx" type="URLRewriter.RewriterFactoryHandler, URLRewriter" />
      <add verb="*" path="*.html" type="URLRewriter.RewriterFactoryHandler, URLRewriter" />
    </httpHandlers>

3.配置重写URL规则  (这里我们就以 *.html转到*.aspx为例子,当然也可以实现 http://www.a.com/a-1.html 转到 http://www.a.com/a.aspx?id=1   这种形式),

在configuration 加入一下节点

view plaincopy to clipboardprint?
<RewriterConfig>  
    <Rules>  
      <RewriterRule>  
        <LookFor>~/(.*).html</LookFor>  
        <SendTo>~/$1.aspx</SendTo>  
      </RewriterRule>  
    </Rules>  
  </RewriterConfig>  
<RewriterConfig>
    <Rules>
      <RewriterRule>
        <LookFor>~/(.*).html</LookFor>
        <SendTo>~/$1.aspx</SendTo>
      </RewriterRule>
    </Rules>
  </RewriterConfig>

4.这一步  也是最重要的一步。在iis 中右键项目→属性→主目录→配置→映射→添加

可执行文件里面输入 c:\windows\microsoft.net\framework\v2.0.50727\aspnet_isapi.dll,

扩展名输入  .html

然后再把 确认文件是否存在 前面的钩钩去掉。(这步很重要,不然会爆404的错误)

如下图所示:

 

5.您需要在你的项目中引用 URLRewriter.dll 这个dll文件  。

下载地址: http://download.csdn.net/source/2325865

6.这样 就配置完了,假设  你有 http://192.168.0.2/index.aspx  这个页面的话。

那么你在浏览器中输入 http://192.168.0.2/index.html 就看到效果了.

注:以上 是在 server2003  iis 6.0  framework2.0 下配置的。

附上 完整的Web.Config代码吧

view plaincopy to clipboardprint?
<?xml version="1.0"?>   
<configuration>   
  <!--1-->   
  <configSections>   
    <section name="RewriterConfig" type="URLRewriter.Config.RewriterConfigSerializerSectionHandler, URLRewriter"/>   
  </configSections>   
  
  
  <appSettings/>   
  <connectionStrings/>   
  <system.web>   
    <compilation debug="true"/>   
    <authentication mode="Windows"/>   
  
    <!--2-->   
    <httpHandlers>   
      <add verb="*" path="*.aspx" type="URLRewriter.RewriterFactoryHandler, URLRewriter" />   
      <add verb="*" path="*.html" type="URLRewriter.RewriterFactoryHandler, URLRewriter" />   
    </httpHandlers>   
  </system.web>   
  
  <!--3-->   
  <RewriterConfig>   
    <Rules>   
      <RewriterRule>   
        <LookFor>~/(.*).html</LookFor>   
        <SendTo>~/$1.aspx</SendTo>   
      </RewriterRule>   
    </Rules>   
  </RewriterConfig>   
  
</configuration>


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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值