[applicationhost.config] [unlock sections] HTTP Error 500.19 - Internal Server Error - Error Code: 0x80070021

.NET Framework MVC project 加入多元認證登入 (windowsAuthentication & anonymousAuthentication) 後,出現錯誤 HTTP Error 500.19 - Internal Server Error - Error Code: 0x80070021 。

透過 Microsoft 官方網站參考資料,修改 applicationhost.config,unlock sections ,解決問題。

.NET Framework MVC project 加入多元認證登入 (windowsAuthentication & anonymousAuthentication) 後,出現錯誤 HTTP Error 500.19 - Internal Server Error - Error Code: 0x80070021 。

錯誤畫面:

google 錯誤資訊,出現Microsoft 官方網站參考資料:開啟 IIS 網頁時出現「HTTP Error 500.19 - Internal Server Error」錯誤  

 HRESULT 代碼 0x80070021

錯誤訊息:

應用程式 "application name" 中有伺服器錯誤
HTTP 錯誤 500.19 – 內部伺服器錯誤
HRESULT: 0x80070021
HRESULT 的描述
無法存取要求的網頁,因為與該網頁相關的設定資料不正確。

原因

當 IIS 設定檔案的指定部分鎖定在較高的設定層級時,可能就會發生這個問題。

解決方案

請解除鎖定指定的區段,或不要在較高層次使用它。 如需有關設定鎖定的詳細資訊,請參閱如何在 IIS 7.0 配置中使用鎖定

在他的解決方案中,提到網頁How to Use Locking in IIS 7.0 Configuration,Task 1: Locking a Section Using a <location> Tag。

在專案資料夾內 .vs\config\applicationhost.config 內有提到

        The recommended way to unlock sections is by using a location tag:
       <location path="Default Web Site" overrideMode="Allow">
           <system.webServer>
               <asp />
           </system.webServer>
       </location>

所以我在 <location path="Default Web Site"> 加入 overrideMode="Allow" attribute 

並註解掉<anonymousAuthentication enabled="false" />

問題就解決了