SqlRoleProvider.GetRolesForUser Method (String)
Gets a list of the roles that a user is in.
Assembly: System.Web (in System.Web.dll)
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. -or- username is longer than 256 characters. |
| System.Configuration.Provider.ProviderException | An unknown error occurred while communicating with the database. |
The GetRolesForUser method is called by the Roles class to retrieve a list of a specified user's roles from the SQL Server database specified in the ASP.NET application's configuration file (Web.config).
The following code example uses the GetRolesForUser method to retrieve a list of roles for a specified user and binds them to a System.Web.UI.WebControls.GridView control. For an example of a Web.config file that enables role management, see SqlRoleProvider.
Available since 2.0