This documentation is archived and is not being maintained.

WindowsTokenRoleProvider::IsUserInRole Method (String, WindowsBuiltInRole)

Gets a value indicating whether the specified user is in the specified built-in Windows role.

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

public:
bool IsUserInRole(
	String^ username, 
	WindowsBuiltInRole role
)

Parameters

username
Type: System::String

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

role
Type: System.Security.Principal::WindowsBuiltInRole

The Windows role to search in.

Return Value

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

ExceptionCondition
System::ArgumentNullException

username is nullptr.

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.

The IsUserInRole method enables you to check whether a user is in one of the common Windows roles described by the WindowsBuiltInRole enumeration. This method is useful for applications that are localized into multiple languages. This overload of the IsUserInRole method is not part of the RoleProvider base class and can only be accessed by casting the Provider property of the Roles class as the WindowsTokenRoleProvider type.

You can call the IsUserInRole method only for the currently logged-on user, as identified by the LOGON_USER server variable. If the value supplied in the username parameter is not the name of the currently logged-on user, an HttpException is thrown.

IsUserInRole method can only be called for the currently logged-on user 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 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: