ClientRolePrincipal クラス

定義

クライアント アプリケーション サービスのセキュリティ情報を表します。これにはロール情報が含まれます。

public ref class ClientRolePrincipal : System::Security::Principal::IPrincipal
public class ClientRolePrincipal : System.Security.Principal.IPrincipal
type ClientRolePrincipal = class
    interface IPrincipal
Public Class ClientRolePrincipal
Implements IPrincipal
継承
ClientRolePrincipal
実装

次のコード例では、このクラスを使用して、ユーザーが "マネージャー" ロールの場合にのみボタンを表示する方法を示します。 この例では、 Button の初期Visibleプロパティ値を持つ という名前managerOnlyButtonfalse必要です。

private void DisplayButtonForManagerRole()
{
    try
    {
        ClientRolePrincipal rolePrincipal =
            System.Threading.Thread.CurrentPrincipal 
            as ClientRolePrincipal;

        if (rolePrincipal != null && rolePrincipal.IsInRole("manager"))
        {
            managerOnlyButton.Visible = true;
        }
    }
    catch (System.Net.WebException)
    {
        MessageBox.Show("Unable to access the roles service.",
            "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
    }
}
Private Sub DisplayButtonForManagerRole()

    Try

        Dim rolePrincipal As ClientRolePrincipal = TryCast( _
            System.Threading.Thread.CurrentPrincipal, ClientRolePrincipal)

        If rolePrincipal IsNot Nothing And _
            rolePrincipal.IsInRole("manager") Then

            managerOnlyButton.Visible = True

        End If

    Catch ex As System.Net.WebException

        MessageBox.Show("Unable to access the role service.", _
            "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning)

    End Try

End Sub

注釈

クライアント アプリケーション サービスでユーザーを検証すると、 ClientFormsAuthenticationMembershipProvider または によって ClientWindowsAuthenticationMembershipProvider プロパティがこのクラスのインスタンスに設定されます staticThread.CurrentPrincipal 。 は ClientFormsAuthenticationMembershipProvider 、 クラスの Identity 新しいインスタンスに対して プロパティを ClientFormsIdentity 初期化します。 はClientWindowsAuthenticationMembershipProvider、 メソッドによって返される オブジェクトにWindowsIdentity対して プロパティをstaticWindowsIdentity.GetCurrent()初期化Identityします。

通常、このクラスには直接アクセスしません。 通常、 プロパティによってstaticCurrentPrincipal返される のメソッドをIPrincipal呼び出IsInRoleします。 ただし、「例」セクションで CurrentPrincipal 示されているように、プロパティ値を ClientRolePrincipal 参照にキャストしてメソッドを明示的に呼び出 IsInRole すことができます。

コンストラクター

ClientRolePrincipal(IIdentity)

ClientRolePrincipal クラスの新しいインスタンスを初期化します。

プロパティ

Identity

ClientRolePrincipal セキュリティ ID を取得します。

メソッド

Equals(Object)

指定されたオブジェクトが現在のオブジェクトと等しいかどうかを判断します。

(継承元 Object)
GetHashCode()

既定のハッシュ関数として機能します。

(継承元 Object)
GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
IsInRole(String)

ClientRolePrincipal が示すユーザーが、指定したロールに存在するかどうかを示す値を取得します。

MemberwiseClone()

現在の Object の簡易コピーを作成します。

(継承元 Object)
ToString()

現在のオブジェクトを表す文字列を返します。

(継承元 Object)

適用対象

こちらもご覧ください