User.IsInRole 方法

定義

判斷目前使用者是否屬於指定角色。

多載

名稱 Description
IsInRole(BuiltInRole)

判斷目前使用者是否屬於指定角色。

IsInRole(String)

判斷目前使用者是否屬於指定角色。

IsInRole(BuiltInRole)

判斷目前使用者是否屬於指定角色。

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

參數

role
BuiltInRole

內建的 Windows 角色用來檢查成員資格。

傳回

True如果目前使用者是指定角色的成員;否則,。 False

範例

此範例在存取資源前檢查使用者是否為管理員。

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

備註

My.User.IsInRole 方法允許您的程式碼判斷目前使用者是否屬於指定角色。

取字串的方法的過載 My.User.IsInRole 讓它能輕鬆存取 IsInRole 當前主體的方法。

接收BuiltInRole列舉的方法的過載My.User.IsInRole行為會因當前原理而異。 若是Windows使用者主體(WindowsPrincipal),此函式會將 role 轉換為等價的 WindowsBuiltInRole 枚舉,並回傳呼叫 IsInRole 的結果。 若當前主體為其他主體,該函數會將列舉值 role 的名稱傳入主體的方法 IsInRole

Note

物件的 My.User 具體行為取決於應用程式的類型以及執行該應用程式所使用的作業系統。 欲了解更多資訊,請參閱 User 課程概述。

依專案類型提供可用性

專案類型 Available
Windows 應用程式 Yes
類別庫 Yes
主控台應用程式 Yes
Windows 控件庫 Yes
Web 控制庫 Yes
Windows 服務 Yes
網站 Yes

另請參閱

適用於

IsInRole(String)

判斷目前使用者是否屬於指定角色。

public:
 bool IsInRole(System::String ^ role);
public bool IsInRole(string role);
member this.IsInRole : string -> bool
Public Function IsInRole (role As String) As Boolean

參數

role
String

要查詢會員資格的職位名稱。

傳回

True如果目前使用者是指定角色的成員;否則,。 False

範例

此範例在存取資源前檢查使用者是否為管理員。

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

備註

My.User.IsInRole 方法允許您的程式碼判斷目前使用者是否屬於指定角色。

取字串的方法的過載 My.User.IsInRole 讓它能輕鬆存取 IsInRole 當前主體的方法。

接收BuiltInRole列舉的方法的過載My.User.IsInRole行為會因當前原理而異。 若是Windows使用者主體(WindowsPrincipal),此函式會將 role 轉換為等價的 WindowsBuiltInRole 枚舉,並回傳呼叫 IsInRole 的結果。 若當前主體為其他主體,該函數會將列舉值 role 的名稱傳入主體的方法 IsInRole

Note

物件的 My.User 具體行為取決於應用程式的類型以及執行該應用程式所使用的作業系統。 欲了解更多資訊,請參閱 User 課程概述。

依專案類型提供可用性

專案類型 Available
Windows 應用程式 Yes
類別庫 Yes
主控台應用程式 Yes
Windows 控件庫 Yes
Web 控制庫 Yes
Windows 服務 Yes
網站 Yes

另請參閱

適用於