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 属性初始化 IdentityWindowsIdentity 方法 staticWindowsIdentity.GetCurrent() 返回的 对象。

通常不会直接访问此类。 通常,将调用 IsInRole 属性返回的 IPrincipal 的 方法 staticCurrentPrincipal 。 但是,可以将属性值ClientRolePrincipal强制转换为CurrentPrincipal引用以显式调用 IsInRole 方法,如示例部分所示。

构造函数

ClientRolePrincipal(IIdentity)

初始化 ClientRolePrincipal 类的新实例。

属性

Identity

获取与 ClientRolePrincipal 关联的安全标识符。

方法

Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetType()

获取当前实例的 Type

(继承自 Object)
IsInRole(String)

获取一个值,该值指示由 ClientRolePrincipal 表示的用户是否扮演指定的角色。

MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
ToString()

返回表示当前对象的字符串。

(继承自 Object)

适用于

另请参阅