aspx转化为html(伪静态)

从提高网站的访问速度和搜索引擎的收录考虑,有时候我们需要把动态的aspx转换为静态的html,这种转换分为两种:伪静态和真静态!这两种各有优劣,今天先不考虑这个,讲讲伪静态是怎么完成的

首先我们要有Mircosoft URLRewriter.dll 如果没有就从网上下载,然后将他们考到项目的bin下面

       其次,就是在web.config中配置相关,这也是最重要的

       

<?xml version="1.0"?>
<configuration>
  <configSections>
    <section name="RewriterConfig" type="URLRewriter.Config.RewriterConfigSerializerSectionHandler, URLRewriter" />
  </configSections>

  <RewriterConfig>
        <Rules>
            <RewriterRule>
                <LookFor>~/web/new/type/(.[0-9]*)\.html</LookFor>
        <SendTo>~/web/new.aspx?id=$1</SendTo>
            </RewriterRule>
      <RewriterRule>
        <LookFor>~/web/index.html</LookFor>
        <SendTo>~/web/index.aspx</SendTo>
      </RewriterRule>
        </Rules>
    </RewriterConfig>
    <system.web>
    <httpHandlers>
      <add verb="*" path="*.aspx" type="URLRewriter.RewriterFactoryHandler, URLRewriter" />
      <add verb="*" path="*.html" type="URLRewriter.RewriterFactoryHandler, URLRewriter" />
    </httpHandlers>
        <compilation debug="true"/></system.web>
</configuration>

蓝色的部门很重要,可以根据需要添加修改;

如带参数的时候Product_List.aspx?Pid=1&page=1

配置文件:<LookFor>~/Product_List(\d+)_(\d+)\.htm</LookFor>
          <SendTo>~/Product_List.aspx?Pid=$1&amp;page=$2</SendTo>

&amp:表示多个参数时的连接符号

网页中设置:Product_List+Pid参数+_+page参数+".htm"

发布到IIS是时候,也要做相关处理

右键点我的电脑-->管理-->展开'服务和应用程序'-->internet信息服务-->找到你共享的目录-->右键点击属性 -->点击'配置'-->映射下面 -->找到.aspx的可执行文件路径复制路径-->添加-->粘贴路径-->扩展名为".html"-->然后把检查文件是否存在的勾去掉这样就可以了,如果遇到“确定”按钮失效,可以用键盘事件编辑路径即可解决

原文地址:https://www.cnblogs.com/qfb620/p/1736278.html