当前位置: 移动技术网 > IT编程>开发语言>.net > 伪静态web.config配置步骤

伪静态web.config配置步骤

2017年12月12日  | 移动技术网IT编程  | 我要评论
复制代码 代码如下:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<!--第一步注册url重写模块放到webconfig的最上部-->
<configsections>
<section name="rewriterconfig" type="urlrewriter.config.rewriterconfigserializersectionhandler, urlrewriter" />
</configsections>
<!--第二步添加重写规则-->
<rewriterconfig>
<!--先制定全部重写规则内容-->
<rules>
<!--制定每个单独页面的规则-->
<rewriterrule>
<!--原始请求地址-->
<sendto><![cdata[~/news.aspx?id=$1&pid=$2]]></sendto>
<!--重写后的地址-->
<lookfor>~/news/(.[0-9]*)/(.[\d]*)\.html</lookfor>
</rewriterrule>
<rewriterrule>
<!--原始请求地址-->
<sendto><![cdata[~/product.aspx?pid=$1]]></sendto>
<!--重写后的地址-->
<lookfor>~/product/(.[\d]*)\.zangdalei</lookfor>
</rewriterrule>
</rules>
</rewriterconfig>
<system.web>
<compilation debug="false" targetframework="4.0">
<!--第四部url重写防止真实的页面也被重写如果网站中真实存在页面,需要添加编译指令不编译真实的html文件-->
<buildproviders>
<add extension=".html" type="system.web.compilation.pagebuildprovider" />
</buildproviders>
</compilation>
<!--第三部url重写 将用户的请求页面交给相应的处理程序,注意请求的后缀名格式-->
<httphandlers>
<add verb="*" path="*.html" type="urlrewriter.rewriterfactoryhandler, urlrewriter" />
<add verb="*" path="*.zangdalei" type="urlrewriter.rewriterfactoryhandler, urlrewriter" />
</httphandlers>
</system.web>
<system.webserver>
<handlers>
<add name="aspnethtml" path="*.html" verb="get,post" modules="isapimodule" scriptprocessor="c:\windows\microsoft.net\framework\v4.0.30319\aspnet_isapi.dll" resourcetype="unspecified" precondition="classicmode,runtimeversionv4.0,bitness32" />
<add name="aspnetzangdalei" path="*.zangdalei" verb="get,post" modules="isapimodule" scriptprocessor="c:\windows\microsoft.net\framework\v4.0.30319\aspnet_isapi.dll" resourcetype="unspecified" precondition="classicmode,runtimeversionv4.0,bitness32" />
</handlers>
<defaultdocument>
<files>
<clear />
<add value="default.aspx" />
<add value="default.html" />
</files>
</defaultdocument>
</system.webserver>
</configuration>

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网