1.伪静态:http://www.cnblogs.com/Default.html 目的就是为了赢得更多的收入,至于真否,待SEOer 解答,正如文字所说,伪静态就是假的静态。

2.准备工作:下载UrlRewrite /Files/Simcoder/URLRewriter.rar 将它放在应用程序bin目录下并引用。

3.配置 IIS 选择主目录 然后 点击配置

找到 “编辑”

找到“插入”:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll 在C盘找到 aspnet_isapi.dll 文件

去掉 确认文件是否存在 下面也是找到该aspnet_isapi.dll 文件 去掉 确认文件是否存在 然后扩展名改为:.html

这些都很简单关键在配置,在网上看了一些资料,越看越迷糊,算了自己搞吧。

4.不得不承认还是得啰嗦和他们一样的: **** ****之间就是需要 复制的代码了

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <configSections>

    <!--******************************************************************************** -->
        <section name="RewriterConfig" type="URLRewriter.Config.RewriterConfigSerializerSectionHandler, URLRewriter" />
    <!--******************************************************************************** -->
    </configSections>  
    <system.web>

<httpHandlers>
        <remove verb="*" path="*.asmx"/>    

  <!--******************************************************************************** -->
          <add verb="*" path="*.aspx" type="URLRewriter.RewriterFactoryHandler, URLRewriter"/>
          <add verb="*" path="*.html" type="URLRewriter.RewriterFactoryHandler, URLRewriter"/>
    <!--******************************************************************************** -->
           </httpHandlers>
      <httpModules>
        <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      </httpModules>
    </system.web>
    <!--******************************************************************************** -->
    <RewriterConfig>
        <Rules>
            <RewriterRule>
                <LookFor>~/index.html</LookFor>
                <SendTo>~/index.aspx</SendTo>
            </RewriterRule>
    </RewriterConfig>
    <!--******************************************************************************** -->
</configuration>

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <configSections>
    <!--******************************************************************************** -->
        <section name="RewriterConfig" type="URLRewriter.Config.RewriterConfigSerializerSectionHandler, URLRewriter" />
    <!--******************************************************************************** -->
    </configSections>  
    <system.web>       <httpHandlers>
        <remove verb="*" path="*.asmx"/>    
  <!--******************************************************************************** -->
          <add verb="*" path="*.aspx" type="URLRewriter.RewriterFactoryHandler, URLRewriter"/>
          <add verb="*" path="*.html" type="URLRewriter.RewriterFactoryHandler, URLRewriter"/>
    <!--******************************************************************************** -->
           </httpHandlers>
      <httpModules>
        <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
      </httpModules>
    </system.web>
    <!--******************************************************************************** -->
    <RewriterConfig>
        <Rules>
            <RewriterRule>
                <LookFor>~/index.html</LookFor>
                <SendTo>~/index.aspx</SendTo>
            </RewriterRule>
    </RewriterConfig>
    <!--******************************************************************************** -->
</configuration>

5.事先在index.aspx页面做好标记,比如Helloworld!打开首页 http://localhost/index.html  发现实际运行的是index.aspx页面

这就是简单的伪静态了。

6.正则表达式:

 <RewriterRule>
    <LookFor>~/(.*).html</LookFor>
    <SendTo>~/$1.aspx</SendTo>
 </RewriterRule>       

(.*):应用于根目录下所有页面;

$1:与(.*)对应,也就是url显示的是什么对应的就是哪个aspx,如index.html对应index.aspx

有时候我们需要多个参数

<RewriterRule>
    <LookFor>~/ProductClassList-(.[0-9][0-9][0-9]*)-(.*).html</LookFor>
     <SendTo><![CDATA[~/productclasslist.aspx?cn=$1&c=$2]]></SendTo>
</RewriterRule>


<RewriterRule>
    <LookFor>~/ProductClassList-(.[0-9][0-9][0-9]*)-(.*).html</LookFor>
     <SendTo><![CDATA[~/productclasslist.aspx?cn=$1&c=$2]]></SendTo>
</RewriterRule>

如果你的文本含有大量的"<" 或"&"字符—就象程序码中经常的那样 — XML元素可以被定义为一个CDATA部分。

还有一个需要注意的是:

url路径匹配的时候,当找到第一个匹配的就不会再匹配第二个。

如根目录index.html 会匹配:<LookFor>~/(.*).html</LookFor>  就不在匹配其他节点。不清楚的可参考URL路由。

所以在配置的时候需要注意各个节点的优先,比如<LookFor>~/(.*).html</LookFor> 我就将它放在配置文件最后一个,

因为他匹配所有目录下的文件。全部配置如下:

<RewriterConfig>
        <Rules>
            <RewriterRule>
                <LookFor>~/productclass-(.[0-9][0-9][0-9]*).html</LookFor>
                <SendTo><![CDATA[~/productclass.aspx?cn=$1]]></SendTo>
            </RewriterRule>
            <RewriterRule>
                <LookFor>~/productclass-(.*)-(.*).html</LookFor>
                <SendTo><![CDATA[~/productclass.aspx?cn=$1&p=$2]]></SendTo>
            </RewriterRule>
            <RewriterRule>
                <LookFor>~/newsinfo-(.*).html</LookFor>
                <SendTo><![CDATA[~/newsinfo.aspx?n=$1]]></SendTo>
            </RewriterRule>
            <RewriterRule>
                <LookFor>~/newsinfo-(.*)-(.*).html</LookFor>
                <SendTo><![CDATA[~/newsinfo.aspx?cn=$1&pn=$2]]></SendTo>
            </RewriterRule>
            <RewriterRule>
                <LookFor>~/ProductClassList-(.*)-(.*)-(.*)-(.*).html</LookFor>
                <SendTo><![CDATA[~/productclasslist.aspx?cn=$1&c=$2&p=$3&s=$4]]></SendTo>
            </RewriterRule>
            <RewriterRule>
                <LookFor>~/ProductClassList-(.[0-9][0-9][0-9]*)-(.*).html</LookFor>
                <SendTo><![CDATA[~/productclasslist.aspx?cn=$1&c=$2]]></SendTo>
            </RewriterRule>
           
            <RewriterRule>
                <LookFor>~/product_detal-(.*)-(.*).html</LookFor>
                <SendTo><![CDATA[~/product_detal.aspx?cn=$1&pn=$2]]></SendTo>
            </RewriterRule>
            <RewriterRule>
                <LookFor>~/product-(.*)-(.*).html</LookFor>
                <SendTo><![CDATA[~/product.aspx?cn=$1&c=$2]]></SendTo>
            </RewriterRule>
            <RewriterRule>
                <LookFor>~/User/(.*).html</LookFor>
                <SendTo>~/User/$1.aspx</SendTo>
            </RewriterRule>
            <RewriterRule>
                <LookFor>~/about/(.*).html</LookFor>
                <SendTo>~/about/$1.aspx</SendTo>
            </RewriterRule>
            <RewriterRule>
                <LookFor>~/NewPro-(.*).html</LookFor>
                <SendTo>~/NewPro.aspx?p=$1</SendTo>
            </RewriterRule>
            <RewriterRule>
                <LookFor>~/prosearch-(.*).html</LookFor>
                <SendTo>~/prosearch.aspx?key=$1</SendTo>
            </RewriterRule>
            <RewriterRule>
                <LookFor>~/(.*).html</LookFor>
                <SendTo>~/$1.aspx</SendTo>
            </RewriterRule>           
        </Rules>
    </RewriterConfig>
</configuration>


    <RewriterConfig>
        <Rules>
            <RewriterRule>
                <LookFor>~/productclass-(.[0-9][0-9][0-9]*).html</LookFor>
                <SendTo><![CDATA[~/productclass.aspx?cn=$1]]></SendTo>
            </RewriterRule>
            <RewriterRule>
                <LookFor>~/productclass-(.*)-(.*).html</LookFor>
                <SendTo><![CDATA[~/productclass.aspx?cn=$1&p=$2]]></SendTo>
            </RewriterRule>
            <RewriterRule>
                <LookFor>~/newsinfo-(.*).html</LookFor>
                <SendTo><![CDATA[~/newsinfo.aspx?n=$1]]></SendTo>
            </RewriterRule>
            <RewriterRule>
                <LookFor>~/newsinfo-(.*)-(.*).html</LookFor>
                <SendTo><![CDATA[~/newsinfo.aspx?cn=$1&pn=$2]]></SendTo>
            </RewriterRule>
            <RewriterRule>
                <LookFor>~/ProductClassList-(.*)-(.*)-(.*)-(.*).html</LookFor>
                <SendTo><![CDATA[~/productclasslist.aspx?cn=$1&c=$2&p=$3&s=$4]]></SendTo>
            </RewriterRule>
            <RewriterRule>
                <LookFor>~/ProductClassList-(.[0-9][0-9][0-9]*)-(.*).html</LookFor>
                <SendTo><![CDATA[~/productclasslist.aspx?cn=$1&c=$2]]></SendTo>
            </RewriterRule>
           
            <RewriterRule>
                <LookFor>~/product_detal-(.*)-(.*).html</LookFor>
                <SendTo><![CDATA[~/product_detal.aspx?cn=$1&pn=$2]]></SendTo>
            </RewriterRule>
            <RewriterRule>
                <LookFor>~/product-(.*)-(.*).html</LookFor>
                <SendTo><![CDATA[~/product.aspx?cn=$1&c=$2]]></SendTo>
            </RewriterRule>
            <RewriterRule>
                <LookFor>~/User/(.*).html</LookFor>
                <SendTo>~/User/$1.aspx</SendTo>
            </RewriterRule>
            <RewriterRule>
                <LookFor>~/about/(.*).html</LookFor>
                <SendTo>~/about/$1.aspx</SendTo>
            </RewriterRule>
            <RewriterRule>
                <LookFor>~/NewPro-(.*).html</LookFor>
                <SendTo>~/NewPro.aspx?p=$1</SendTo>
            </RewriterRule>
            <RewriterRule>
                <LookFor>~/prosearch-(.*).html</LookFor>
                <SendTo>~/prosearch.aspx?key=$1</SendTo>
            </RewriterRule>
            <RewriterRule>
                <LookFor>~/(.*).html</LookFor>
                <SendTo>~/$1.aspx</SendTo>
            </RewriterRule>           
        </Rules>
    </RewriterConfig>
</configuration>

$1:对应第一个(.*)

$2:对应第二个(.*)

$3:对应第三个(.*)

$4:对应第四个(.*)

...依次类推

然后就是页面连接的更改,将aspx更改为html,如果有带参数的或者分页,我是直接在文件名 加"-"分隔参数;

Request.CurrentExecutionFilePath.Substring(0, Request.CurrentExecutionFilePath.LastIndexOf("aspx"))+"-参数-参数-参数...."+".html";

这种办法不适合做大型项目,不过小项目很快就能完成,尤其是已经做好的网站只需半天或一天就修改完成了。

作者:网站运营 小绿虫博客

出处:http://www.cnblogs.com/simcoder

本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则小绿虫很生气后果很严重.

(转)ASP.NET 伪静态的更多相关文章

  1. ASP.NET伪静态实现

    ASP.NET伪静态实现 在asp.net下,如何自己写代码来实现伪静态呢?如何重写url地址呢? 例如:本来aspx的页面地址是:/default.aspx?id=1,我要重写成这样:/index- ...

  2. ASP.NET伪静态的方法及相关资料

    1. 添加URLRewriter.dll引用 2. 配置web.config的基本信息 <configSections> <section name="RewriterCo ...

  3. 原创:分享asp.net伪静态成目录形式iis如何设置

    服务器租用详解asp.net伪静态成目录形式iis如何设置: 一.首先介绍一下asp.net伪静态成html后缀iis如何设置的 iis6 伪静态 iis配置方法 图解 1.右键点击 要设置网站的网站 ...

  4. [转载]ASP.NET伪静态页面的实现和伪静态在IIS7.0中的配置

    ASP.NET伪静态 UrlRewrite(Url重写) 实现和配置 最近在写一个CMS的内容管理系统,需要用到一个伪静态方面的方法,在网上找了一下这方面的资料,现将这方面的资源记录一下. 本机环境: ...

  5. ASP.NET伪静态

    http://www.duote.com/tech/5/14543.html 三.伪静态的坏处 当然犹如一篇文章的作者所说的:"如果流量稍大一些使用伪静态就出现CPU使用超负荷,我的同时在线 ...

  6. ASP.NET伪静态 UrlRewrite(Url重写) 实现和配置

    核心提示:大家一定经常在网络上看到很多网站的地址后缀都是用XX.HTML或者XX.ASPX等类似静态文件的标示来操作的吧,那么大家有怀疑过他真的是一个一个的静态生成的文件么,静态文件的生成的优缺有好有 ...

  7. ASP.NET伪静态-无法读取配置文件,因为它超过了最大文件大小的解决办法

    一直都在使用微软URLRewriter,具体的使用方法我就不多说了,网上文章很多. 但最近遇到一个问题,就是当web.config文件里面设置伪静态规则过多,大于2M的时候,就报错:无法读取配置文件, ...

  8. 解决 asp.net 伪静态 IIS设置后 直正HTML无法显示的问题

    asp.net+UrlRewriter来实现网站伪静态,实现伪静态有一些好处,比如对于搜索引擎更好收录页面,还有一个好处就是隐藏了真实地址的参数,所以有独立服务器的朋友,配置IIS实现伪静态功能,挺不 ...

  9. ASP.NET伪静态配置

    一.下载URLRewriter.dll 二.在项目中添加URLRewrite的引用 三.配置webconfig 1.在<configuration>节点中添加: <configSec ...

随机推荐

  1. HDU 4614 (13年多校第二场1004)裸线段树

    题意:给你N个花瓶,编号是0  到 N - 1 ,初始状态花瓶是空的,每个花瓶最多插一朵花. 然后有2个操作. 操作1,a b c ,往在a位置后面(包括a)插b朵花,输出插入的首位置和末位置. 操作 ...

  2. DBA优化SQL采用的WITH AS 用法简介

    一.WITH AS简介 WITH AS的用法从oracle 9i新增的,官方文档也称之为:subquery factoring;在进行复杂的查询.统计等操作时使用with as 子句可以大大提高性能! ...

  3. Secure CRT 如何连接虚拟机里面的CentOS系统——当主机使用无线网的时候 作者原创 欢迎转载

    第一步:设置自己的无线网,并且分享给VM8这个虚拟网卡 第二步:查看VM8网卡的IP地址,如图是192.168.137.1 第三步:设置虚拟机的配置:选择VM8网卡并且是NAT的 第四步:设置虚拟机里 ...

  4. java学习笔记(11) —— Struts2与Spring的整合

    1.右键 项目名称 —— MyEclipse —— Add Spring Capabilities 2.选取 Copy checked Library contents to project fold ...

  5. NGINX关于配置PATHINFO

    最近在群里发现有很多小白不会配置pathinfo现贴出来配置代码照着配置就可以了     1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 2 ...

  6. pyenv简介——Debian/Ubuntu中管理多版本Python

    pyenv简介——Debian/Ubuntu中管理多版本Python MAY 21ST, 2016 12:00 AM | COMMENTS pyenv是管理Python版本的工具,它支持在多个Pyth ...

  7. toast组件较为完美版本

    <!DOCTYPE html><html lang="en"> <head> <meta charset="UTF-8" ...

  8. 开个CS5.4编译编译,调试错误贴

    记录各种编译,调试中遇到问题.

  9. Retina 显示屏

    Retina 直接翻译是视网膜的意思.在IT上,是Apple 公司提出的.意思是指一个显示屏的颗粒度 px 密度高到人类无法看见.要了解细节必须先了解基础知识inch 英寸 1 inch = 2.52 ...

  10. 检测客户端显示器分辨率、浏览器类型和客户端IP

    原文:检测客户端显示器分辨率.浏览器类型和客户端IP 下面的代码实现了检测客户端显示器分辨率.浏览器类型和客户端IP的功能.你可以把客户端信息保存到Session,ViewState等中以便在其它的页 ...