IIRF重寫在asp.net4.0+IIS6中部分失敗的解決方案

來源:互聯網
上載者:User

    最近公司開始了一個新項目,使用的是asp.net mvc3、asp.net4.0、iis6。因為在iis6中不能支援無副檔名的路徑。所以想到了使用Url重寫。

    思路是這樣的,在iis中添加.mvc的副檔名映射到C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319/aspnet_isapi.dll,這樣就可以使用/home.mvc/index這樣的路徑,然後使用url重寫

    RewriteRule ^/home/index/$ /home.mvc/index/ [I,L,U]

    這樣就解決了以上的問題。但是在實踐中一直顯示404錯誤。

    原因如下:

    ASP.NET 4.0在安裝的時候,會在IIS6註冊一個ISAPI Filter,叫做”aspnet_filter.dll”,ISAPI Filter會先於ISAPI處理常式前執行,它會在所有的的無尾碼的URL後面加一串字元“/eurl.axd/GUID”, 同時ASP.NET 4.0還會在IIS預設添加一個請求映射規則“*.axd”,映射到aspnet_isapi.dll。此時,所有的無尾碼URL加上“/eurl.axd/GUID”後都會變成帶.axd尾碼,這樣就匹配*.axd的映射規則進行ASP.NET的處理通道。在進入ASP.NET通道後,ASP.NET處理常式會刪除掉“/eurl.axd/GUID”,讓它還原到無尾碼的原始情況,並且不會對後續的請求處理帶來任何影響。此時,所有的無尾碼請求,就進入了ASP.NET的處理通道中,在預設情況下,ASP.NET4.0的全域的web.config中配置了DefaultHttpHandler來接收無尾碼的URL請求,但是我們也可以隨意更換預設處理常式(比如ASP.NET MVC處理常式)來處理無尾碼的URL請求。

    ASP.NET 4.0在IIS6原生支援沒有尾碼名的URL請求

 

   

    解決方案:移除aspnet_filter.dll

http://www.asp.net/learn/whitepapers/aspnet4/breaking-changes#0.1__Toc256770153

   

If it is not practical to remap the Web site to ASP.NET 2.0 or to change the location of a virtual directory, explicitly disable extensionless URL processing in ASP.NET 4. Use the following procedure:

  1. In the Windows registry, open the following node:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ASP.NET\4.0.30319.0

  1. Create a new DWORD value named EnableExtensionlessUrls.
  2. Set EnableExtensionlessUrls to 0. This disables extensionless URL behavior.
  3. Save the registry value and close the registry editor.
  4. Run the iisreset command-line tool, which causes IIS to read the new registry value.

 

 

 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.