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 アプリケーション はい
クラス ライブラリ はい
コンソール アプリケーション はい
Windows コントロール ライブラリ はい
Web コントロール ライブラリ はい
Windows サービス はい
Web サイト はい

適用対象

こちらもご覧ください