Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

ClientRolePrincipal Class

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

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

'Declaration
Public Class ClientRolePrincipal _
	Implements IPrincipal
'Usage
Dim instance As ClientRolePrincipal

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 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

System.Object
  System.Web.ClientServices.ClientRolePrincipal

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

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

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

.NET Framework

Supported in: 3.5

Community Additions

ADD
Show:
© 2015 Microsoft