HTTP 500.19 錯誤多因 ASP.NET 父網站與子網站因繼承關係導致設定項目重複,過去曾經歷幾次(IIS 7限制IP存取的設定錯誤、怪異的web.config HttpHandler重複錯誤),今天再遇到 IP 限制設定重複導致子網站掛點的狀況,同事發誓一切操作合情合理,想想上回 IIS 7 IP 限制設定打架案例沒有逆天亂搞照樣出錯,推測其中有雷,決定現場模擬還原真相。
我在 IIS 設定一獨立站台 Test,其下加入 Child 子網站。父網站的 index.html 以 IFrame 內嵌 Child/index.html 進行測試。

透過 IIS 管理介面設定 Test 站台拒絕未指定的 IP 用戶端。

接著在 Test 站台設定允許 IP ::1(IPv6 的 Localhost)

檢視 Child 子網站的 IP 位址及網域限制,可發現已自動加上 ::1,這是繼承自 Test 站台的設定。

接著在 Child 另外加入一筆 127.0.0.1,此時瀏覽 localhost:7611 仍正常。

如果我們在 Test 站台也加入 127.0.0.1,就會變成以下德行,重現今天遇到的狀況:

Child/index.html 詳細錯誤如下:
HTTP 錯誤 500.19 - Internal Server Error
無法存取要求的網頁,因為與該網頁相關的設定資料不正確。詳細錯誤資訊:
模組 IpRestrictionModule
通知 BeginRequest
處理常式 ExtensionlessUrlHandler-Integrated-4.0
錯誤碼 0x800700b7
設定錯誤 在複合金鑰屬性 'ipAddress, subnetMask, domainName' 分別設為 '127.0.0.1, 255.255.255.255, ' 的情況下,無法新增類型 'add' 的重複集合項目
設定檔案 \\?\C:\inetpub\temp\apppools\Test\Test.config
要求的 URL http://localhost:7611/Child/
實體路徑 X:\WWW\Child\
登入方法 尚未判定
登入使用者 尚未判定設定來源:
835: <ipSecurity>
836: <add ipAddress="127.0.0.1" allowed="true" />
837: </ipSecurity>詳細資訊:
如果讀取網頁伺服器或 Web 應用程式的設定檔案發生問題,此時就會發生這種錯誤。在某些情況下,事件記錄可能會包含何種原因造成這項錯誤的詳細資訊。
檢視詳細資訊 »
由此可知:
先在子網站加入限制 IP,再到父網站加入相同限制 IP,就會因繼承關係造成子網站設定重複,觸發 500.19 錯誤!
發生問題後,子網站的「IP 位址及網域限制」已無法開啟,除了直接修改 IIS config 檔,必須先移除父網站的重複 IP 設定,才能使用 IIS 管理介面重設子網站的 IP 限制。

結論是 IIS 缺少防呆,無法防範或忽略繼承設定與子網站設定重複的狀況,只能操作時多加留意。