Export (0) Print
Expand All

ClientRolePrincipal Class

Represents security information for client application services, which includes role information.

System.Object
  System.Web.ClientServices.ClientRolePrincipal

Namespace:  System.Web.ClientServices
Assembly:  System.Web.Extensions (in System.Web.Extensions.dll)

public class ClientRolePrincipal : IPrincipal

The ClientRolePrincipal type exposes the following members.

  NameDescription
Public methodClientRolePrincipalInitializes a new instance of the ClientRolePrincipal class.
Top

  NameDescription
Public propertyIdentityGets the security identity associated with the ClientRolePrincipal.
Top

  NameDescription
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodIsInRoleGets a value indicating whether the user represented by the ClientRolePrincipal is in the specified role.
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

When you validate a user in client application services, the ClientFormsAuthenticationMembershipProvider or the ClientWindowsAuthenticationMembershipProvider sets the static Thread.CurrentPrincipal property to an instance of this class. The ClientFormsAuthenticationMembershipProvider initializes the Identity property to a new instance of the ClientFormsIdentity class. The ClientWindowsAuthenticationMembershipProvider initializes the Identity property to the WindowsIdentity object returned by the static WindowsIdentity.GetCurrent() method.

You will not typically access this class directly. Normally, you will call the IsInRole method of the IPrincipal returned by the static CurrentPrincipal property. However, you can cast the CurrentPrincipal property value to a ClientRolePrincipal reference to call the IsInRole method explicitly, as demonstrated in the Example section.

The following example code demonstrates how to use this class to display a button only when the user is in the "manager" role. This example requires a Button named managerOnlyButton with an initial Visible property value of false.

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);
    }
}

.NET Framework

Supported in: 4.5, 4, 3.5

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2014 Microsoft