WindowsTokenRoleProvider.IsUserInRole Method (String, String)

Gets a value indicating whether the specified user is in the specified Windows group.

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

public:
virtual bool IsUserInRole (
	String^ username, 
	String^ roleName
) override
public boolean IsUserInRole (
	String username, 
	String roleName
)
public override function IsUserInRole (
	username : String, 
	roleName : String
) : boolean
Not applicable.

Parameters

username

The user name to search for in the form DOMAIN\username.

roleName

The Windows group to search in the form DOMAIN\rolename.

Return Value

true if the specified user name is in the specified Windows group; otherwise, false.

Exception typeCondition

System.ArgumentNullException

username is a null reference (Nothing in Visual Basic).

-or-

roleName is a null reference (Nothing in Visual Basic).

System.Configuration.Provider.ProviderException

The currently executing user does not have an authenticated WindowsIdentity attached to Page.User. For non-HTTP scenarios, the currently executing user does not have an authenticated WindowsIdentity attached to Thread.CurrentPrincipal.

-or-

username does not match the Name of the current WindowsIdentity.

-or-

A failure occurred while retrieving the user's Windows group information.

The IsUserInRole method is called by the Roles class and the IsInRole method of the User property to determine whether a user is in a Windows group. You can call the IsUserInRole method only for the currently logged-on user, as identified by the LOGON_USER server variable. The current logged-on user must be a Windows authenticated user. For more information on ASP.NET and Windows authentication, see ASP.NET Authentication.

The following code example programmatically checks whether the currently logged-on user is in the Administrators role before allowing the user to view roles information for the application. For an example of a Web.config file that enables role management, see WindowsTokenRoleProvider.

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: