您的位置:首页 > 其它

IIS7下使用URLRewriter的配置

2011-04-30 10:18 183 查看
引用Lixy的博文使用MicrosoftURLRewriteModuleforIIS7.0修改WEB.CONFIG即可实现*.HTML伪静态无需修改应用程序映射:在IIS5和IIS6时代,我们使用URLREWRITING可实现URL重写,使得WEB程序实现伪静态,但默认情况下只能实现.ASPX的伪静态,如果要实现伪静态*.HTML的页面,需要将ISAPI里面的*.HTML应用程序映射改为.NET的ISAPI。但在IIS7时代,这一切已经变得非常简单了,您在WEB.CONFIG中就可以管理这一切了。

可我今天改的程序是我以前写的,在II6中配置实现的伪静态,现在在IIS7中跑也不想去重配置伪静态规则了,所就想在IIS7中实现URLRewriter的配置。

一:和IIS6一样在<configSections>节点下配置

<configuration> <configSections> <sectionname="RewriterConfig"type="URLRewriter.Config.RewriterConfigSerializerSectionHandler,URLRewriter"/> </configSections> <RewriterConfig> <Rules> <RewriterRule> <LookFor>~/about/feedback\.html</LookFor> <SendTo><![CDATA[~/About/FeedBack.aspx]]></SendTo> </RewriterRule> </Rules> </RewriterConfig> <httpModules> <addname="ModuleRewriter"type="URLRewriter.ModuleRewriter,URLRewriter"/> </httpModules>

二:在IIS7中将ISAPI里面的*.HTML应用程序映射改为.NET的ISAPI

在“处理程序映射”中添加脚本映射配置如下

点击确定的时候会自动在Web.Config中添加
<handlers>
<removename="WebServiceHandlerFactory-Integrated"/>
<removename="ScriptHandlerFactory"/>
<removename="ScriptHandlerFactoryAppServices"/>
<removename="ScriptResource"/>
<addname="HtmlHandler"path="*.html"verb="*"modules="IsapiModule"scriptProcessor="C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll"

resourceType="Unspecified"preCondition="classicMode,runtimeVersionv2.0,bitness32"/> </handlers>

[/code]
三:如我的站点为:http://192.168.1.3/则http://192.168.1.3/about/feedback.html是可以正常打开的也就说我们伪静态配置好了,
但可当你打开原本就是.html文件(如我站点下的stiemap.html)当我打开http://192.168.1.3/sitemap.html时,问题出现了:

“/”应用程序中的服务器错误。

没有为扩展名“.html”注册的生成提供程序。可以在machine.config或web.config中的

<compilation><buildProviders>节注册一个。请确保所注册的提供程序具有包含值“Web”或“All”的

BuildProviderAppliesToAttribute属性。

这时要做如下配置:
<compilationdebug="true">
<!--加上此节点,保证原本就是.html类型的文件能正常访问-->
<buildProviders>
<addextension=".html"type="System.Web.Compilation.PageBuildProvider"/>
</buildProviders>
</compilation>





内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐