简体   繁体   English

URL重写和IIS Express:有些规则有效,有些则无效

[英]URL Rewrite and IIS Express: some rules work, some don't

I'm using IIS Express to develop an MVC 3 application which is doing some URL rewriting in web.config. 我正在使用IIS Express开发MVC 3应用程序,该应用程序正在web.config中进行一些URL重写。 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 ) (来源: https : //stackoverflow.com/a/8089525/88709

This one doesn't (gives Unrecognized attribute 'url' in the second line): 这个没有(在第二行中给出了Unrecognized attribute '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>

(source: http://blogs.iis.net/ruslany/archive/2009/04/08/10-url-rewriting-tips-and-tricks.aspx ) (来源: 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. 根据ScottGu的IIS Express 简介 ,IIS Express启用了完整的Web服务器功能集-包括SSL, URL重写,媒体支持和所有其他IIS 7.x模块。

I was inclined to believe that maybe the URL Rewrite module that ships with IIS Express is the 1.0 version, not 2.0. 我倾向于认为IIS Express附带的URL Rewrite模块可能是1.0版本,而不是2.0版本。 So I installed URL Rewrite Module 2.0 , but I still get the same error. 所以我安装了URL Rewrite Module 2.0 ,但是仍然出现相同的错误。

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. 如果有问题,我的设置是Visual Studio 2010 SP1,IIS Express 7.5.1070,ASP.NET MVC 3。

The problem was that I placed the <rule> in the wrong node; 问题是我将<rule>放在了错误的节点上。 '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). “删除尾部斜杠”规则应该放在<rules></rules> ,但是我错误地将其放置在<outboundRules></outboundRules> (BTW是“删除ETag”规则的所在)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM