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.

.NET Framework

Supported in: 4, 3.5

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Show: