2009-10-02 29 views
0

我想用一些簡單的認證編寫一個簡單的內部應用程序。我也試圖通過web.config快速學習表單身份驗證。存儲用戶信息/通過web.config認證

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

但是,我很難在web.config文件中存儲要檢查的用戶/通行證。

的MSDN手冊上說把這個進入的web.config:

<authentication mode="Forms"> 
    <forms loginUrl="login.aspx"> 
     <credentials passwordFormat="SHA1"> 
      <user name="user1" password="27CE4CA7FBF00685AF2F617E3F5BBCAFF7B7403C" /> 
      <user name="user2" password="D108F80936F78DFDD333141EBC985B0233A30C7A" /> 
      <user name="user3" password="7BDB09781A3F23885CD43177C0508B375CB1B7E9"/> 
     </credentials> 
    </forms> 
</authentication> 

然而,分鐘,我加上「憑證」到「認證」部分,我得到這個錯誤:

Server Error in '/' Application. 
Configuration Error 
Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately. 

Parser Error Message: Unrecognized element 'credentials'. 

Source Error: 

Line 44:  <authentication mode="Forms"> 
Line 45:  <forms loginUrl="login.aspx" /> 
Line 46:  <credentials> 
Line 47:   
Line 48:  </credentials> 


Source File: C:\inetpub\wwwroot\asp\projects\passwordCatalog\passwordCatalog\web.config Line: 46 

所以我的問題是,我將如何以及在哪裏將以下內容添加到web.config文件中?

<credentials passwordFormat="SHA1"> 
    <user name="johndoe" password="mypass123" /> 
</credentials> 
+0

消息指審查的具體錯誤的詳細信息。是否有特定的錯誤?如果是這樣,請發佈。 – klabranche 2009-10-02 03:24:03

+0

好的,我添加了上面的其餘部分。 – 2009-10-02 04:18:37

回答

3

的<憑證>元素應該被嵌套在形成元件內部。

你的錯誤信息表明這是不是這樣:您已關閉的形式元素上線45(<形式... />的代替<形式...>

Line 44:  <authentication mode="Forms"> 
Line 45:  <forms loginUrl="login.aspx" /> 
Line 46:  <credentials> 
Line 47:   
Line 48:  </credentials> 

你想要的是:

<authentication mode="Forms"> 
    <forms loginUrl="login.aspx"> 
     <credentials> 
     ... 
     </credentials> 
    </forms> 
    ... 
+0

OH男人...這就是我得到的深夜編碼。我無法想象出我的生活......這是我自己的視線。非常感謝! – 2009-10-02 21:30:46

0

使用passwordFormat="Clear"

<authentication mode="Forms"> 
    <forms loginUrl="default.aspx"> 
     <credentials passwordFormat="Clear"> 
    <user name="user1" password="pass1"/> 
     </credentials> 
    </forms> 
</authentication> 
+0

嗨,酷......我會在哪裏放置「憑據」? MSDN正在說嵌入它的'身份驗證'內,但這是拋出錯誤 – 2009-10-02 04:19:17