Roles::AddUserToRole Method (String^, String^)

 

Adds the specified user to the specified role.

Namespace:   System.Web.Security
Assembly:  System.Web (in System.Web.dll)

public:
static void AddUserToRole(
	String^ username,
	String^ roleName
)

Parameters

username
Type: System::String^

The user name to add to the specified role.

roleName
Type: System::String^

The role to add the specified user name to.

Exception Condition
System::ArgumentNullException

roleName is null.

-or-

username is null.

System::ArgumentException

roleName is an empty string or contains a comma (,).

-or-

username is an empty string or contains a comma (,).

System.Configuration.Provider::ProviderException

Role management is not enabled.

-or-

User is already assigned to the specified role.

The AddUserToRole method calls the default role provider to associate the specified user with the specified role at the data source.

System_CAPS_noteNote

User names and role names cannot contain commas.

The following code example adds a user to a role. For an example of a Web.config file that enables role management, see Roles.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 2.0
Return to top
Show: