在 IIS 7 中啟用 URL Rewrite 將 .html 交由 ASP.NET 處理後,原本存在的靜態 HTML 檔案可能無法存取,出現「未能執行 URL」錯誤。原因在於 ASP.NET 管線不再自動處理靜態檔案,需手動註冊 StaticFileHandler。
系統錯誤: System.Web.HttpException: 未能執行 URL。
在 <system.webServer> 區段下的 <handlers>(IIS 7+ 整合模式)或 <httpHandlers>(經典模式)加入:
<system.webServer>
<handlers>
<add name="StaticFileHandler-HTML"
path="*.html"
verb="*"
type="System.Web.StaticFileHandler"
preCondition="integratedMode" />
</handlers>
</system.webServer>
<system.web>
<httpHandlers>
<add verb="*" path="*.html" type="System.Web.StaticFileHandler" />
</httpHandlers>
</system.web>
*.html 對應至 ASP.NET 管線。StaticFileHandler。StaticFileHandler 直接回傳。web.config。.html 頁面。Content-Type: text/html 且內容正確。此設定相容共存:偽靜態 .html 走 MVC/WebForms,真實靜態 .html 由 IIS 直接服務,互不干擾。