Click to Rate and Give Feedback
MSDN
MSDN Library
Visual Studio 2008
Visual Studio
Visual Basic
My.User Object
 IsInRole Method (My.User Object)

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
Visual Basic Language Reference
My.User.IsInRole Method

Determines whether the current user belongs to the specified role.

' Usage
Dim value As Boolean = My.User.IsInRole(role)
Dim value As Boolean = My.User.IsInRole(role)
' Declaration
Public Function IsInRole( _
   ByVal role As String _
) As Boolean
' -or-
Public Function IsInRole( _
   ByVal role As BuiltInRole _
) As Boolean
role

String or BuiltInRole Enumeration. The role for which to check membership.

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

The My.User.IsInRole method lets your code to determine whether 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 My.User Object.

To

See

Determine the user's role

How to: Determine if a User is in a Group

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

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

Namespace: Microsoft.VisualBasic.ApplicationServices

Class: User, WebUser

Assembly: Visual Basic Runtime Library (in Microsoft.VisualBasic.dll)

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

The following permission may be required:

Permission

Description

SecurityPermission

Describes a set of security permissions applied to code. Associated enumeration: ControlPrincipal.

For more information, see Code Access Security and Requesting Permissions.

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker