Roles.AddUsersToRoles Method
Assembly: System.Web (in system.web.dll)
public static void AddUsersToRoles ( String[] usernames, String[] roleNames )
public static function AddUsersToRoles ( usernames : String[], roleNames : String[] )
Not applicable.
Parameters
- usernames
A string array of user names to add to the specified roles.
- roleNames
A string array of role names to add the specified user names to.
| Exception type | Condition |
|---|---|
|
One of the roles in roleNames is a null reference (Nothing in Visual Basic). -or- One of the users in usernames is a null reference (Nothing in Visual Basic). | |
|
One of the roles in roleNames is an empty string or contains a comma (,). -or- One of the users in usernames is an empty string or contains a comma (,). -or- roleNames contains a duplicate element. -or- usernames contains a duplicate element. | |
|
Role management is not enabled. |
The AddUsersToRoles method calls the default role provider to associate the specified users with the specified roles at the data source.
If your application uses the SqlRoleProvider class, the database updates that are performed during the call to the AddUsersToRoles method are made within a transaction. If an error is encountered, such as a user name that is already in a specified role, the transaction is rolled back and no updates are performed.
Note: |
|---|
|
User names and role names cannot contain commas. |
Reference
Roles ClassRoles Members
System.Web.Security Namespace
Note: