ClientRoleProvider::IsUserInRole Method (String^, String^)
Gets a value indicating whether the specified user is in the specified role.
Assembly: System.Web.Extensions (in System.Web.Extensions.dll)
Parameters
- username
-
Type:
System::String^
The name of the user.
- roleName
-
Type:
System::String^
The name of the role.
Return Value
Type: System::Booleantrue if the specified user is in the specified role; false if the specified user is not authenticated or is not in the specified role.
| Exception | Condition |
|---|---|
| ArgumentException | |
| WebException | The user is no longer authenticated. -or- The roles service is not available. |
You can determine whether an authenticated user is in a particular role by calling the IsInRole method of the IPrincipal returned by the static Thread::CurrentPrincipal property. For applications configured to use client application services, this property returns a ClientRolePrincipal. Because this class implements the IPrincipal interface, you do not need to reference it explicitly. The ClientRolePrincipal::IsInRole method internally calls the IsUserInRole method. The IsUserInRole method uses the GetRolesForUser method to determine whether the user indicated by username is in the role indicated by roleName.
The service provider caches role information about the local file system to avoid unnecessary service calls. For more information, see the ClientRoleProvider class overview.
The following example code demonstrates how to access this method directly to determine whether the user is in a particular role. This code first tests whether the user login has expired. An explicit ClientRoleProvider reference is required to call the GetRolesForUser method, so the same reference is used to call the IsUserInRole method. If the user is in the "manager" role, this code calls a PerformManagerTask method, which is not provided.
Available since 3.5