Export (0) Print
Expand All

User.IsInRole Method (String)

Determines whether the current user belongs to the specified role.

Namespace:  Microsoft.VisualBasic.ApplicationServices
Assembly:  Microsoft.VisualBasic (in Microsoft.VisualBasic.dll)

public bool IsInRole(
	string role
)

Parameters

role
Type: System.String

The name of the role for which to check membership.

Return Value

Type: System.Boolean
True if the current user is a member of the specified role; otherwise, False.

The My.User.IsInRole method allows your code to determine if the current user is a member of the specified role.

The overload of the My.User.IsInRole method that takes a string provides easy access to the IsInRole method of the current principal.

The overload of the My.User.IsInRole method that takes a BuiltInRole enumeration behaves differently, depending on the current principal. If it is a Windows user principal (WindowsPrincipal), this function converts role to the equivalent WindowsBuiltInRole enumeration and returns the result of calling IsInRole. If the current principal is any other principal, this function passes the name of the enumeration value in role to the principal's IsInRole method.

NoteNote

The exact behavior of the My.User object depends on the type of the application and on the operating system on which the application runs. For more information, see the User class overview.

Availability by Project Type

Project type

Available

Windows Application

Yes

Class Library

Yes

Console Application

Yes

Windows Control Library

Yes

Web Control Library

Yes

Windows Service

Yes

Web Site

Yes

This example checks if the user is an administrator before accessing a resource.

If My.User.IsInRole( 
        ApplicationServices.BuiltInRole.Administrator) Then 
    ' Insert code to access a resource here. 
End If

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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

Show:
© 2014 Microsoft