System.Security.Permissions.PrincipalPermissionAttribute Class

Allows security actions for System.Security.Permissions.PrincipalPermission to be applied to code using declarative security. This class cannot be inherited.

See Also: PrincipalPermissionAttribute Members

Syntax

[System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Method | System.AttributeTargets.All, AllowMultiple=true, Inherited=false)]
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class PrincipalPermissionAttribute : CodeAccessSecurityAttribute

Remarks

System.Security.Permissions.PrincipalPermissionAttribute can be used to declaratively demand that users running your code belong to a specified role or have been authenticated. Use of PermissionState.Unrestricted creates a System.Security.Permissions.PrincipalPermission with PrincipalPermissionAttribute.Authenticated set to true and PrincipalPermissionAttribute.Name and PrincipalPermissionAttribute.Role set to null.

The scope of the declaration that is allowed depends on the System.Security.Permissions.SecurityAction that is used. System.Security.Permissions.PrincipalPermissionAttribute cannot be applied at the assembly level.

The security information declared by a security attribute is stored in the metadata of the attribute target and is accessed by the system at run time. Security attributes are used only for declarative security. For imperative security, use the corresponding permission class.

Note:

Before you use this class to demand principal permission, you must set the current application domain's principal policy to the enumeration value System.Security.Principal.PrincipalPolicy.WindowsPrincipal. By default, the principal policy is set to System.Security.Principal.PrincipalPolicy.UnauthenticatedPrincipal. If you do not set the principal policy to System.Security.Principal.PrincipalPolicy.WindowsPrincipal, a demand for principal permission will fail. The following code should be executed before the principal permission is demanded: AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal).

Requirements

Namespace: System.Security.Permissions
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0