Forms Authentication – Managing Users
While there are a lot of controls available in ASP.NET that allow you to manage forms authentication, one control that doesn’t exist is something that will allow you to manage your user list.
Most of the time you don’t need this, but when you do, there is an obvious hole.
Since we need to write this code ourselves, how do access the user list from our code?
The Membership API built into ASP.NET gives you access to the user information and a lot more.
To access the list of users, you’ll need to call Membership.GetAllUsers();
Since I like working with datasets because of their flexibility, I create a DataTable that has the information I want to store and loop through the collection that Membership.GetAllUsers() returns and fill the DataTable.
DataSetContentEditors.LoginsDataTable logins =
new DataSetContentEditors.LoginsDataTable();
MembershipUserCollection muc = Membership.GetAllUsers();
foreach (MembershipUser mu in muc)
{
logins.AddLoginsRow(mu.UserName);
}
To change the password for the user, you can call the MembershipUser’s ResetPassword to generate a new password and then call the ChangePassword() method to set it to what you want it to be.
MembershipUser u = Membership.GetUser(userName);
string resetPassword = u.ResetPassword();
u.ChangePassword(resetPassword, newPassword);
Other post in forms authentication
- WordPress w/ Forms Authentication on IIS6 - May 21st, 2008
- Setting Up Your Forms Based Authentication Database - September 14th, 2009
- Forms Authentication – Creating Users - September 21st, 2009
- Forms Authentication – Managing Users - September 28th, 2009
- Forms Authentication – Manual Authentication - October 5th, 2009
- Determine The Role of a User in ASP.NET - October 13th, 2009
- ASP.NET Assigning a Role to a User - October 19th, 2009
- Authentication - Assigning Permissions to Roles - October 26th, 2009
Other Related Items:
MCSA/MCSE Self-Paced Training Kit (Exam 70-290): Managing and Maintaining a Microsoft Windows Server 2003 EnvironmentAnnouncing an all-new MCSA/MCSE Training Kit designed to help maximize your performance on Exam 70-290, a core exam for the new Windows Server 2003 ce... Read More >
Wicket in ActionThere are dozens of Java frameworks out there, but most of them require you to learn special coding techniques and new, often rigid, patterns of de... Read More >
MCSA/MCSE Self-Paced Training Kit (Exam 70-291): Implementing, Managing, and Maintaining a Microsoft Windows Server 2003 Network Infrastructure (Pro Certification)Announcing an all-new MCSA/MCSE Training Kit designed to help maximize your performance on Exam 70-291, a core exam for the new Windows Server 2003 ce... Read More >
If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!









