2014-06-06 82 views
2

我需要使用URL重寫,所以我做了一個試驗的情況下,在Web.config中,要檢查它的工作:URL重寫與Web.config文件不IIS工作表現

Web.config文件:

<system.webServer> 
<rewrite> 
    <rules> 
    <rule name="Fail bad requests"> 
     <match url=".*"/> 
     <action type="AbortRequest" /> 
    </rule> 
    </rules> 
</rewrite> 
... other stuff 
</system.webServer> 

我期待任何localhost:3285中止和失敗,但它輸入正確。

我使用的是帶有IIS Express的Url Rewrite

回答

2

我猜你的問題是瀏覽器緩存。我發現如果我在IE中打開一個網頁,然後添加URL重寫規則(需要停止IIS express),然後在IE中再次打開相同的頁面,它仍然加載頁面(並且看起來中止規則沒有被應用) 。但是,如果我清除IE瀏覽器緩存並刷新頁面,則會發生中止。

這裏是一個充滿Web.config的例子,對我的作品

<?xml version="1.0" encoding="utf-8"?> 
<!-- 
    For more information on how to configure your ASP.NET application, please visit 
    http://go.microsoft.com/fwlink/?LinkId=169433 
    --> 
<configuration> 
    <system.web> 
    <compilation debug="true" targetFramework="4.5" /> 
    <httpRuntime targetFramework="4.5" /> 
    </system.web> 
    <system.webServer> 
    <rewrite> 
     <rules> 
     <rule name="Fail bad requests"> 
      <match url=".*"/> 
      <action type="AbortRequest" /> 
     </rule> 
     </rules> 
    </rewrite> 
    </system.webServer> 
</configuration> 

你的榜樣應該工作,因爲URL重寫模塊內置到當前版本的IIS快遞: http://www.iis.net/learn/extensions/introduction-to-iis-express/iis-express-overview