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.
public final boolean IsInRole (
	String role
)
public final function IsInRole (
	role : String
) : boolean
Not applicable.

Parameters

role

The role to search for.

Return Value

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

Exception typeCondition

ProviderException

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

IsInRole first checks IsRoleListCached to see if there is a cached list of role names for the current user. If the IsRoleListCached property is true, then the cached list is checked for the specified role. When role names are cached in a cookie, both allowed role names and denied role names are cached for the user. If the IsInRole method finds the specified role in the cached list of allowed role names, then it will return true. If the IsInRole method finds the specified role in the cached list of denied role names, then it will return false. If IsInRole does not find the specified role in either the allowed or denied list of role names, then it will call the IsUserInRole method of the default role Provider to determine whether a user name is associated with a role from the data source for the configured ApplicationName.

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 98, Windows Server 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions

ADD
Show: