URL 重写和 IIS Express:有些规则有效,有些则无效
我正在使用 IIS Express 开发一个 MVC 3 应用程序,该应用程序在 web.config 中进行一些 URL 重写。我遇到了一些奇怪的情况,其中一些规则完美运行,而另一些规则却失败了。
例如,这个有效:(
<rule name="Remove ETag">
<match serverVariable="RESPONSE_ETag" pattern=".+" />
<action type="Rewrite" value="" />
</rule>
来源:https://stackoverflow.com/a/8089525/88709)
这个没有't(在第二行给出无法识别的属性'url'
):(
<rule name="Remove trailing slash" stopProcessing="true">
<match url="(.*)/$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="{R:1}" />
</rule>
来源:http://博客。 iis.net/ruslany/archive/2009/04/08/10-url-rewriting-tips-and-tricks.aspx)
根据IIS Express 简介,作者:ScottGu,IIS Express 支持完整的 Web 服务器功能集 - 包括 SSL、URL 重写、媒体支持以及所有其他 IIS 7.x 模块。
我倾向于相信 IIS Express 附带的 URL 重写模块可能是 1.0 版本,而不是 2.0。所以我安装了URL重写模块2.0,但我仍然遇到同样的错误。
有人知道为什么会发生这种情况吗?如果重要的话,我的设置是 Visual Studio 2010 SP1、IIS Express 7.5.1070、ASP.NET MVC 3。
I'm using IIS Express to develop an MVC 3 application which is doing some URL rewriting in web.config. I have ran into a bit of an oddity where some of the rules work perfectly, while others fail.
For example this one works:
<rule name="Remove ETag">
<match serverVariable="RESPONSE_ETag" pattern=".+" />
<action type="Rewrite" value="" />
</rule>
(source: https://stackoverflow.com/a/8089525/88709)
This one doesn't (gives Unrecognized attribute 'url'
in the second line):
<rule name="Remove trailing slash" stopProcessing="true">
<match url="(.*)/$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="{R:1}" />
</rule>
(source: http://blogs.iis.net/ruslany/archive/2009/04/08/10-url-rewriting-tips-and-tricks.aspx)
According to Introducing IIS Express, by ScottGu, IIS Express enables a full web-server feature set – including SSL, URL Rewrite, Media Support, and all other IIS 7.x modules.
I was inclined to believe that maybe the URL Rewrite module that ships with IIS Express is the 1.0 version, not 2.0. So I installed URL Rewrite Module 2.0, but I still get the same error.
Does anybody have a clue why this happens? In case it matters, my setup is Visual Studio 2010 SP1, IIS Express 7.5.1070, ASP.NET MVC 3.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是我将
放置在错误的节点中; “删除尾部斜杠”规则应该位于
内部,但我错误地将其放置在
中(顺便说一句,这是“删除 ETag”规则所在的位置)。The problem was that I placed the
<rule>
in the wrong node; 'Remove trailing slash' rule is supposed to go inside<rules></rules>
, but I incorrectly placed it in<outboundRules></outboundRules>
(which BTW is where the 'Remove ETag' rule goes).