2012-02-03 61 views
2

我正在嘗試編寫一個簡單的身份驗證。我也試圖通過web.config快速學習表單身份驗證。無法識別的元素'身份驗證'。

所以我有我的身份驗證工作,如果我硬編碼我的'用戶名'和'密碼'到C#代碼並做一個簡單的條件。

但是,我收到en錯誤消息'無法識別的元素'身份驗證'。

Line 2:  <system.web> 
Line 3:   <customErrors mode="off"> 
Line 4:    <authentication mode="Forms"> 
Line 5:     <forms name=".C#FEWD" 
Line 6:      loginUrl="/schools/admin/login/index.aspx" 

我的web.config文件看起來是這樣的:

<configuration> 
    <system.web> 
     <customErrors mode="off"> 
      <authentication mode="Forms"> 
       <forms name=".C#FEWD" 
        loginUrl="/schools/admin/login/index.aspx" 
        protection="All" 
        timeout="60"> 
        <credentials passwordFormat="Clear"> 
         <user name="schools" password="magic" /> 
        </credentials> 
       </forms> 
      </authentication> 
     <authorization> 
      <deny users="?" /> 
     </authorization> 
     </customErrors> 
    </system.web> 
</configuration> 

回答

3

它可能只是你缺少從您的customErrors節點終止設置:

<customErrors mode="off"/> 

更多如下評論:

您的完整配置應該是:

<configuration> 
    <system.web> 
     <customErrors mode="off" /> 
     <authentication mode="Forms"> 
      <forms name=".C#FEWD" 
       loginUrl="/schools/admin/login/index.aspx" 
       protection="All" 
       timeout="60"> 
       <credentials passwordFormat="Clear"> 
        <user name="schools" password="magic" /> 
       </credentials> 
      </forms> 
     </authentication> 
     <authorization> 
      <deny users="?" /> 
     </authorization> 
    </system.web> 
</configuration> 
+0

自定義錯誤設置有節點終止符。 – 2012-02-06 11:51:50

+0

Ah - ''不應該是''設置的子節點 - 終止'',並在之後放置<' – 2012-02-06 11:55:18

+0

感謝Jon的工作 – 2012-02-06 12:06:14

0

正如喬恩說,該<authorization>節點不應該是<customErrors>節點的孩子。

相關問題