伪静态的设置可以使诸如xiangqing.aspx?id=426以类似xiangqing-426.html方式显示,利于SEO。方法多种,这次只试用了URLrewriter.dll方法。三步即可。 1.IIS设置 本站点-属性-主目录-配置-映射-添加-可执行文件c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll(同.aspx映射)-扩展名“.html”,限制为“GET,HEAD,POST,DEBUG”-脚本引擎“打勾”-确认文件是否存在“不打勾”-确定。 2.网上下载URLRewriter.dll,拷贝到bin目录,并在vs里添加引用,此时会另生成URLRewriter.dll.refresh文件。 3.修改网页 web.config页面: 第一部分 [backcolor=white !important][backcolor=rgb(224, 224, 224) !important][size=1em]1
[backcolor=white !important][size=1em]2
[backcolor=rgb(224, 224, 224) !important][size=1em]3
[backcolor=white !important][size=1em]4
[backcolor=rgb(224, 224, 224) !important][size=1em]5
[backcolor=white !important][size=1em]6
[backcolor=rgb(224, 224, 224) !important][size=1em]7
[backcolor=white !important][size=1em]8
[backcolor=rgb(224, 224, 224) !important][size=1em]9
[backcolor=white !important][size=1em]10
[backcolor=rgb(224, 224, 224) !important][size=1em]11
[backcolor=white !important][size=1em]12
[backcolor=rgb(224, 224, 224) !important][size=1em]13
[backcolor=white !important][size=1em]14
[backcolor=rgb(224, 224, 224) !important][size=1em]15
| [size=1em][backcolor=rgb(224, 224, 224) !important][size=1em]<configuration>
[backcolor=white !important][size=1em] <configSections>
[backcolor=rgb(224, 224, 224) !important][size=1em] <section name="RewriterConfig"type="URLRewriter.Config.RewriterConfigSerializerSectionHandler, URLRewriter" />
[backcolor=white !important][size=1em] </configSections>
[backcolor=rgb(224, 224, 224) !important][size=1em] <RewriterConfig>
[backcolor=white !important][size=1em] <Rules>
[backcolor=rgb(224, 224, 224) !important][size=1em] <RewriterRule><!--可增加多个-->
[backcolor=white !important][size=1em] <LookFor>~/xiangqing-(.[0-9]*)\.html</LookFor>
[backcolor=rgb(224, 224, 224) !important][size=1em] <SendTo>~/xiangqing.aspx?id=$1</SendTo>
[backcolor=white !important][size=1em] </RewriterRule>
[backcolor=rgb(224, 224, 224) !important][size=1em] <RewriterRule><!--可增加多个-->
[backcolor=white !important][size=1em] <LookFor>~/newsxiangqing-(.[0-9]*)\.html</LookFor>
[backcolor=rgb(224, 224, 224) !important][size=1em] <SendTo>~/newsxiangqing.aspx?id=$1</SendTo>
[backcolor=white !important][size=1em] </RewriterRule> </Rules>
[backcolor=rgb(224, 224, 224) !important][size=1em] </RewriterConfig>
|
。。。 第二部分 [backcolor=white !important][backcolor=rgb(224, 224, 224) !important][size=1em]1
[backcolor=white !important][size=1em]2
[backcolor=rgb(224, 224, 224) !important][size=1em]3
[backcolor=white !important][size=1em]4
[backcolor=rgb(224, 224, 224) !important][size=1em]5
| [size=1em][backcolor=rgb(224, 224, 224) !important][size=1em]<system.web>
[backcolor=white !important][size=1em] <httpHandlers>
[backcolor=rgb(224, 224, 224) !important][size=1em] <add verb="*" path="*.aspx" type="URLRewriter.RewriterFactoryHandler, URLRewriter" />
[backcolor=white !important][size=1em] <add verb="*" path="*.html" type="URLRewriter.RewriterFactoryHandler, URLRewriter" />
[backcolor=rgb(224, 224, 224) !important][size=1em] </httpHandlers>
|
。。。 第三部分 [backcolor=white !important][backcolor=rgb(224, 224, 224) !important][size=1em]1
[backcolor=white !important][size=1em]2
| [size=1em][backcolor=rgb(224, 224, 224) !important][size=1em]<httpModules>
[backcolor=white !important][size=1em] <add type="URLRewriter.ModuleRewriter, URLRewriter" name="ModuleRewriter"/>
|
注:正则表达式可在网上搜索合适的进行修改。
其他相关页面将类似href='xiangqing.aspx?id=<%#DataBinder.Eval(Container.DataItem,"id")%>'的部分修改为 href='xiangqing-<%#DataBinder.Eval(Container.DataItem,"id")%>.html'即可。 如果想让以.aspx后缀显示而不是.html,则在IIS里删除.html脚本映射,web.config里将<LookFor>~/xiangqing-(.[0-9]*)\.html</LookFor>修改为<LookFor>~/xiangqing-(.[0-9]*)\.aspx</LookFor>,并删除<add verb="*" path="*.html" type="URLRewriter.RewriterFactoryHandler, URLRewriter" />部分即可。
|