This documentation is archived and is not being maintained.

ClientRoleProvider::GetRolesForUser Method

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.

ExceptionCondition
ArgumentException

username is Empty or nullptr.

-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.

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5
Show: