网络.配置表单认证获取所有用户



我有一个非常简单的asp.net应用程序,我使用表单身份验证并在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>

我想简单地能够得到所有的用户,然后将他们绑定到下拉列表

您可以阅读web。按照下面的代码配置http://msdn.microsoft.com/en-us/library/4c2kcht0.aspx

我发现从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);
}

最新更新