Roles.GetRolesForUser Method (String)

 

Gets a list of the roles that a user is in.

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

static member GetRolesForUser : 
        username:string -> string[]

Parameters

username
Type: System.String

The user to return a list of roles for.

Return Value

Type: System.String[]

A string array containing the names of all the roles that the specified user is in.

Exception Condition
System.ArgumentNullException

username is null.

System.ArgumentException

username contains a comma (,).

System.Configuration.Provider.ProviderException

Role management is not enabled.

The GetRolesForUser method calls the RoleProvider.GetRolesForUser method of the default role provider to retrieve from the data source the roles that the user is in. Only the roles for the application that is specified in the ApplicationName property are retrieved.

If username is equal to the current logged-on user and CacheRolesInCookie is true, the results of the GetRolesForUser method may be returned from the role cache rather than the specified Provider.

The following code example uses the GetRolesForUser method to retrieve a list of roles for a specified user and bind the returned roles to a System.Web.UI.WebControls.GridView control. 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: