zoukankan      html  css  js  c++  java
  • asp.net实现伪静态页面

    189人阅读评论(0)收藏举报

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

    1.首先在web.config里写

    1. <configSections> 
    2.     <sectionname="RewriterConfig"type="URLRewriter.Config.RewriterConfigSerializerSectionHandler, URLRewriter"/> 
    3.   </configSections> 

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

    1. <httpHandlers> 
    2.       <addverb="*"path="*.aspx"type="URLRewriter.RewriterFactoryHandler, URLRewriter"/> 
    3.       <addverb="*"path="*.html"type="URLRewriter.RewriterFactoryHandler, URLRewriter"/> 
    4.     </httpHandlers> 

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

    在configuration 加入一下节点

    1. <RewriterConfig> 
    2.     <Rules> 
    3.       <RewriterRule> 
    4.         <LookFor>~/(.*).html</LookFor> 
    5.         <SendTo>~/$1.aspx</SendTo> 
    6.       </RewriterRule> 
    7.     </Rules> 
    8.   </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代码吧

    1. <?xml version="1.0"?> 
    2. <configuration> 
    3.   <!--1--> 
    4.   <configSections> 
    5.     <section name="RewriterConfig" type="URLRewriter.Config.RewriterConfigSerializerSectionHandler, URLRewriter"/> 
    6.   </configSections> 
    7.  
    8.  
    9.   <appSettings/> 
    10.   <connectionStrings/> 
    11.   <system.web> 
    12.     <compilation debug="true"/> 
    13.     <authentication mode="Windows"/> 
    14.  
    15.     <!--2--> 
    16.     <httpHandlers> 
    17.       <add verb="*" path="*.aspx" type="URLRewriter.RewriterFactoryHandler, URLRewriter" /> 
    18.       <add verb="*" path="*.html" type="URLRewriter.RewriterFactoryHandler, URLRewriter" /> 
    19.     </httpHandlers> 
    20.   </system.web> 
    21.  
    22.   <!--3--> 
    23.   <RewriterConfig> 
    24.     <Rules> 
    25.       <RewriterRule> 
    26.         <LookFor>~/(.*).html</LookFor> 
    27.         <SendTo>~/$1.aspx</SendTo> 
    28.       </RewriterRule> 
    29.     </Rules> 
    30.   </RewriterConfig> 
    31.  
    32. </configuration> 

  • 相关阅读:
    读书笔记——吴军《态度》
    JZYZOJ1237 教授的测试 dfs
    NOI1999 JZYZOJ1289 棋盘分割 dp 方差的数学结论
    [JZYZOJ 1288][洛谷 1005] NOIP2007 矩阵取数 dp 高精度
    POJ 3904 JZYZOJ 1202 Sky Code 莫比乌斯反演 组合数
    POJ2157 Check the difficulty of problems 概率DP
    HDU3853 LOOPS 期望DP 简单
    Codeforces 148D. Bag of mice 概率dp
    POJ3071 Football 概率DP 简单
    HDU4405 Aeroplane chess 飞行棋 期望dp 简单
  • 原文地址:https://www.cnblogs.com/jhabb/p/2422098.html
Copyright © 2011-2022 走看看