Roles.IsUserInRole Method (String)
Assembly: System.Web (in system.web.dll)
The IsUserInRole method calls the RoleProvider.IsUserInRole method of the default role provider to determine whether the currently logged-on user is associated with a role from the data source for the application that is specified in the ApplicationName property. The currently logged-on user is identified by the System.Web.HttpContext.User property of the current System.Web.HttpContext, or by 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 ApplicationName property are retrieved.
If CacheRolesInCookie is true, then roleName may be checked against the roles cache rather than the specified role provider.
The following code example programmatically checks whether the currently logged-on user is in the Administrators role before allowing the user to view roles settings for the application. For an example of a Web.config file that enables role management, see Roles.
Reference
Roles ClassRoles Members
System.Web.Security Namespace