User.IsInRole Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Determines whether the current user belongs to the specified role.
Overloads
IsInRole(BuiltInRole) |
Determines whether the current user belongs to the specified role. |
IsInRole(String) |
Determines whether the current user belongs to the specified role. |
IsInRole(BuiltInRole)
Determines whether the current user belongs to the specified role.
public:
bool IsInRole(Microsoft::VisualBasic::ApplicationServices::BuiltInRole role);
public bool IsInRole (Microsoft.VisualBasic.ApplicationServices.BuiltInRole role);
member this.IsInRole : Microsoft.VisualBasic.ApplicationServices.BuiltInRole -> bool
Public Function IsInRole (role As BuiltInRole) As Boolean
Parameters
- role
- BuiltInRole
The built-in Windows role for which to check membership.
Returns
True
if the current user is a member of the specified role; otherwise, False
.
Examples
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
Remarks
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.
Note
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 |
See also
Applies to
IsInRole(String)
Determines whether the current user belongs to the specified role.
public:
bool IsInRole(System::String ^ role);
public bool IsInRole (string role);
member this.IsInRole : string -> bool
Public Function IsInRole (role As String) As Boolean
Parameters
- role
- String
The name of the role for which to check membership.
Returns
True
if the current user is a member of the specified role; otherwise, False
.
Examples
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
Remarks
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.
Note
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 |