简体   繁体   中英

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. 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.

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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