ClientRoleProvider::GetRolesForUser Method (String^)

 

Gets the names of the roles that the specified user belongs to.

Namespace:   System.Web.ClientServices.Providers
Assembly:  System.Web.Extensions (in System.Web.Extensions.dll)

public:
virtual array<String^>^ GetRolesForUser(
	String^ username
) override

Parameters

username
Type: System::String^

The name of the user to retrieve roles for.

Return Value

Type: array<System::String^>^

The role names that username belongs to or an empty array if the user is not authenticated.

Exception Condition
ArgumentException

username is Empty or null.

-or-

username is not the user name of the current, authenticated user.

The GetRolesForUser method retrieves role information for the current, authenticated user, which you must specify in the username parameter. You can get the user name through the static Thread::CurrentPrincipal property as follows: Thread.CurrentPrincipal.Identity.Name.

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 use this method to determine whether the user login has expired before testing role membership. This code assumes that all valid users are associated with one or more roles. In this case, the GetRolesForUser method will not return any roles for a previously-authenticated user whose login has expired. If the user login has expired, this code displays the login dialog box. Otherwise, it calls the IsUserInRole method to determine whether the user is in the "manager" role. The restricted code is in a PerformManagerTask method, which is not provided.

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

.NET Framework
Available since 3.5
Return to top
Show: