Reputation: 4469
I am trying to write a simple internal app with some simple authentication. I'm also trying to make this quick and learn about the forms authentication via web.config.
So i have my authentication working if I hard code my 'user name' and 'password' into C# code and do a simple conditional.
However, I'm having a tough time storing the a user/pass to be checked against in the web.config file.
The MSDN manual says to put this into the 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>
However, the minute I add 'credentials' into the 'authentication' section, I get this error:
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
So my question is, how and where would I add the following in the web.config file?
<credentials passwordFormat="SHA1">
<user name="johndoe" password="mypass123" />
</credentials>
Upvotes: 1
Views: 5558
Reputation: 94645
Use passwordFormat="Clear"
<authentication mode="Forms">
<forms loginUrl="default.aspx">
<credentials passwordFormat="Clear">
<user name="user1" password="pass1"/>
</credentials>
</forms>
</authentication>
Upvotes: 1
Reputation: 124696
The <credentials> element should be nested inside the forms element.
Your error message indicates that this isn't the case: you have closed the forms element on line 45 (<forms ... /> instead of <forms ... >)
Line 44: <authentication mode="Forms">
Line 45: <forms loginUrl="login.aspx" />
Line 46: <credentials>
Line 47:
Line 48: </credentials>
What you want is:
<authentication mode="Forms">
<forms loginUrl="login.aspx">
<credentials>
...
</credentials>
</forms>
...
Upvotes: 4