我使用IIS Express來開發一個MVC 3應用程序,它在web.config中執行一些URL重寫。我遇到了一些奇怪的地方,其中一些規則完美地工作,而另一些則失敗。URL重寫和IIS Express:有些規則可以工作,有些不需要
例如,這一個工作的:
<rule name="Remove ETag">
<match serverVariable="RESPONSE_ETag" pattern=".+" />
<action type="Rewrite" value="" />
</rule>
(來源:https://stackoverflow.com/a/8089525/88709)
這一個不(給出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>
(來源: http://blogs.iis.net/ruslany/archive/2009/04/08/10-url-rewriting-tips-and-tricks.aspx)
根據IIS Express支持完整的Web服務器功能集 - 包括SSL,URL重寫,媒體支持以及所有其他IIS 7.x模塊。
我傾向於認爲,IIS Express附帶的URL Rewrite模塊可能是1.0版本,而不是2.0。所以我安裝了URL Rewrite Module 2.0,但我仍然得到相同的錯誤。
有沒有人知道爲什麼會發生這種情況?萬一它很重要,我的設置是Visual Studio 2010 SP1,IIS Express 7.5.1070,ASP.NET MVC 3.
在我的IIS Express上正常工作:s您可能從其他代碼中收到此錯誤。 – tugberk 2012-01-06 12:41:01
@tugberk我剛剛創建了一個新的空MVC項目,將所有內容都設爲默認值,並且僅將刪除尾部斜槓規則添加到web.config中。同樣的錯誤。這兩個規則是否適用於您的IIS Express?這很奇怪。我開始認爲我的設置存在問題... – 2012-01-06 13:43:15
我寫了一篇關於它的博客文章,並且我都在IIS Express上進行了測試:http://www.tugberkugurlu.com/archive/remove-trailing-slash -from-the-urls-of-your-asp-net-web-site-with-iis-7-url-rewrite-module無法弄清楚什麼可能是錯的:s – tugberk 2012-01-06 13:50:23