ClientRolePrincipal Class
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Represents security information for client application services, which includes role information.
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
- Inheritance
-
ClientRolePrincipal
- Implements
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);
}
}
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
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.
Client |
Initializes a new instance of the ClientRolePrincipal class. |
Identity |
Gets the security identity associated with the ClientRolePrincipal. |
Equals(Object) |
Determines whether the specified object is equal to the current object. (Inherited from Object) |
Get |
Serves as the default hash function. (Inherited from Object) |
Get |
Gets the Type of the current instance. (Inherited from Object) |
Is |
Gets a value indicating whether the user represented by the ClientRolePrincipal is in the specified role. |
Memberwise |
Creates a shallow copy of the current Object. (Inherited from Object) |
To |
Returns a string that represents the current object. (Inherited from Object) |
Termék | Verziók |
---|---|
.NET Framework | 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET-visszajelzés
A(z) .NET egy nyílt forráskód projekt. Visszajelzés adásához válasszon egy hivatkozást: