System.Web.Security.Roles.GetRolesForUser Method

Gets a list of the roles that the currently logged-on user is in.

Syntax

public static string[] GetRolesForUser ()

Returns

A string array containing the names of all the roles that the currently logged-on user is in.

Remarks

The Roles.GetRolesForUser method calls the RoleProvider.GetRolesForUser(string) method of the default role provider to retrieve from the data source the roles that the currently logged-on user is in. The currently logged-on user is identified by the System.Web.HttpContext.User property of the current System.Web.HttpContext, or by System.Threading.Thread.CurrentPrincipal for non-HTTP hosting environments. If no user is logged on, an exception will be thrown. Only the roles for the application that is specified in the Roles.ApplicationName property are retrieved.

If Roles.CacheRolesInCookie is true, then the results of the Roles.GetRolesForUser method may be returned from the role cache rather than the specified role provider.

Requirements

Namespace: System.Web.Security
Assembly: System.Web (in System.Web.dll)
Assembly Versions: 2.0.0.0
Since: .NET 2.0