HttpModules/HttpHandlers in IIS7
剛才發現,把網站專案移到Vista/IIS7執行時,原本web.config設定的httpHandlers失效:
<httpHandlers>
....
<add verb="GET" path="DownloadFile.axd" type="Afa.Ajax.WebControl.DownloadHandler" />
</httpHandlers>
連線/DownloadFile.axd時,會傳回HTTP 404找不到檔案的錯誤。
透過IIS7的Internet Information Services (IIS) Manager / Handler Mappings設定UI,重新指定這個HttpHandler,功能就恢復了。但修好的原因是web.config被IIS Manager改過,再一比對,發現IIS Manager在web.config中加入了這一段:
<system.webServer>
<handlers>
....
<add name="DownloadFile" path="DownloadFile.axd" verb="*" type="Afa.Ajax.WebControl.DownloadHandler" resourceType="Unspecified" preCondition="integratedMode" />
</handlers>
</system.webServer>
如果要兼顧IIS6及IIS7,可在web.config中同時保留httpHandlers(for IIS6)及handlers(for IIS7)裡的相同定義,但記得要加上<validation validateIntegratedModeConfiguration="false" />,不然IIS7會因為定義重覆出現而發生錯誤。參考資料