User.CurrentPrincipal プロパティ

定義

現在のプリンシパル (ロールベースのセキュリティ用) を取得または設定します。

public:
 property System::Security::Principal::IPrincipal ^ CurrentPrincipal { System::Security::Principal::IPrincipal ^ get(); void set(System::Security::Principal::IPrincipal ^ value); };
public System.Security.Principal.IPrincipal CurrentPrincipal { get; set; }
member this.CurrentPrincipal : System.Security.Principal.IPrincipal with get, set
Public Property CurrentPrincipal As IPrincipal

プロパティ値

セキュリティ コンテキストを表す IPrincipal 値。

例外

呼び出し元には、プリンシパルを設定するために必要なアクセス許可がありません。

この例では、アプリケーションがWindows認証またはカスタム認証を使用しているかどうかを確認し、その情報を使用して My.User.Name プロパティを解析します。

Function GetUserName() As String
    If TypeOf My.User.CurrentPrincipal Is 
      Security.Principal.WindowsPrincipal Then
        ' The application is using Windows authentication.
        ' The name format is DOMAIN\USERNAME.
        Dim parts() As String = Split(My.User.Name, "\")
        Dim username As String = parts(1)
        Return username
    Else
        ' The application is using custom authentication.
        Return My.User.Name
    End If
End Function

注釈

My.User.CurrentPrincipal プロパティを、カスタム認証を有効にするIPrincipal インターフェイスを実装するオブジェクトに設定できます。

ほとんどのプロジェクトの種類では、このプロパティはスレッドの現在のプリンシパルを取得して設定します。 ASP.NET アプリケーションでは、このプロパティは現在の HTTP 要求のユーザー ID のセキュリティ情報を取得して設定します。

これは上級メンバーです。[ すべて ] タブをクリックしない限り、IntelliSense には表示されません。

プロジェクトの種類別の可用性

プロジェクト タイプ 在庫有り
Windows アプリケーション Yes
クラス ライブラリ Yes
コンソール アプリケーション Yes
Windows コントロール ライブラリ Yes
Web コントロール ライブラリ Yes
Windows サービス Yes
ウェブサイト Yes

適用対象

こちらもご覧ください