ASP.NET Assigning a Role to a User
Another function that is not supplied by one of the existing controls in ASP.NET is the ability to assign a user to a role. For this, we will need to resort to using the APIs.
Since we can assign roles to users using the ASP.NET configuration tool, we can assume there is an API available that will do this work for us.
Here is how it is done.
The first thing we will need to do is to add the roles to the system. The API for this is pretty simple.
using System.Web.Security; if (!Roles.RoleExists("RoleName")) { Roles.CreateRole("RoleName")); }
To attach a user to the role, you call AddUsersToRole. You can add multiple users and/or multiple roles at the same time.
Roles.AddUserToRole("User","Role"); // or Roles.AddUserToRole("User", new string[] {"role1","role2"}); // or Roles.AddUserToRole(new string[] {"user1","user2"},"role"); // or Roles.AddUserToRole( new string[] {"user1","user2"}, new string[] {"role1","role2"});
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:
Jim Kelly Signed Bills Blue JerseyThis blue Buffalo Bills jersey has been signed by Bills Hall of Famer Jim Kelly. It was signed during a private signing, and includes a Certificate of Authenticity from James Spence Authentication. A matching, numbered JSA decal is affixed to the jersey.
SQL queryVent Those Luser Frustrations, SQL Style Too bad you cant use SQL queries in the real world. We suppose it's also too bad that reality (whatever that... Read More >
Payback Time: Making Big Money Is the Best Revenge!Product Description
Dont get mad, get even...
Phil Towns first book, the #1 New York Times bestseller Rule #1, was a guide to stock trading for peop... Read More >









