I have a very simple asp.net application which I'm using forms authentication and storing each user's name / password in开发者_Go百科 the web.config:
<authentication mode="Forms">
<forms name="appNameAuth" path="/" loginUrl="l.aspx" protection="All" timeout="600">
<credentials passwordFormat="Clear">
<user name="user1" password="pass1"/>
<user name="user2" password="pass2"/>
<user name="user3" password="pass3"/>
</credentials>
</forms>
</authentication>
I'd like to simply be able to get all users, then bind them to a dropdownlist.
You can read web.config from code like that http://msdn.microsoft.com/en-us/library/4c2kcht0.aspx
I found that from msdn http://msdn.microsoft.com/en-us/library/system.web.configuration.formsauthenticationconfiguration.credentials.aspx
FormsAuthenticationCredentials currentCredentials = formsAuthentication.Credentials;
StringBuilder credentials = new StringBuilder();
for (System.Int32 i = 0; i < currentCredentials.Users.Count; i++)
{
credentials.Append("Name: " + currentCredentials.Users[i].Name + " Password: " + currentCredentials.Users[i].Password);
credentials.Append(Environment.NewLine);
}
精彩评论