This documentation is archived and is not being maintained.

RolePrincipal.IsInRole Method

Gets a value indicating whether the user represented by the RolePrincipal is in the specified role.

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

No code example is currently available or this language may not be supported.

Parameters

role
Type: System.String

The role to search for.

Return Value

Type: System.Boolean
true if user represented by the RolePrincipal is in the specified role; otherwise, false.

Implements

IPrincipal.IsInRole(String)

ExceptionCondition
ProviderException

The Identity property is a null reference (Nothing in Visual Basic).

IsInRole first checks the IsRoleListCached property to determine whether a cached list of role names for the current user is available. If the IsRoleListCached property is true, the cached list is checked for the specified role. If the IsInRole method finds the specified role in the cached list, it returns true.

If IsInRole does not find the specified role, it calls the GetRolesForUser method of the default Provider instance to determine whether the user name is associated with a role from the data source for the configured ApplicationName value.

The following code example checks to see whether the logged-on user is in the Administrators role before allowing the user to view user roles.

No code example is currently available or this language may not be supported.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0
Show: