首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> 更多程式語言 >> 程式設計疑難解答

ASP.NET web.config 驗證配置錯誤:credentials 子元素無效的排查與修正

     編輯:程式設計疑難解答

錯誤訊息

元素 “authentication” 的子元素 “credentials” 無效

原因

<authentication mode="Forms"> 下的 <forms> 子元素**不包含** <credentials>。credentials 僅用於 mode="Passport"(已淘汰)或舊版 Forms 的 <forms> 內部(且需特定 schema)。

正確結構

<authentication mode="Forms">
  <forms loginUrl="Login.aspx" timeout="30" />
</authentication>

<authorization>
  <deny users="?" />
</authorization>

若需儲存使用者憑證(不推薦)

<authentication mode="Forms">
  <forms loginUrl="Login.aspx">
    <credentials passwordFormat="SHA1">
      <user name="admin" password="sha1_hash" />
    </credentials>
  </forms>
</authentication>

但現代應用應使用 **ASP.NET Identity / Membership / IdentityServer** 管理使用者,勿在 config 明文/哈希存密碼。

排查步驟

    1. 開啟 web.config,定位 <authentication> 區塊。
    2. 移除錯誤的 <credentials> 或移至正確父元素。
    3. 在 Visual Studio 編輯器中,web.config 享有 IntelliSense,輸入 < 即可看到合法子元素,防止拼寫錯誤。
    4. 重新建置部署。
錯誤截圖 修正截圖
  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved