Mono Class Library: System.Security.Permissions Namespace

System.Security.Permissions.EnvironmentPermissionAttribute Class

Used to declaratively specify security actions to control access to environment variables.

See Also: EnvironmentPermissionAttribute Members

System.Object
     System.Attribute
          System.Security.Permissions.SecurityAttribute
               System.Security.Permissions.CodeAccessSecurityAttribute
                    System.Security.Permissions.EnvironmentPermissionAttribute

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

Thread Safety

All public static members of this type are safe for multithreaded operations. No instance members are guaranteed to be thread safe.

Remarks

Environment variable names are case-insensitive. Multiple environment variable names are specified by separating the names using the System.IO.Path.PathSeparator string.

Note:

The level of access to one or more environment variables is specified using the members of the current instance. For example, to specify read permissions for an environment variable, set the EnvironmentPermissionAttribute.Read property equal to the name of the environment variable.

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 for declarative security only. For imperative security, use the corresponding permission class, System.Security.Permissions.EnvironmentPermission .

The allowable System.Security.Permissions.EnvironmentPermissionAttribute targets are determined by the System.Security.Permissions.SecurityAction passed to the constructor.

Example

The following example shows a declarative request for the ability to read the specified environment variables. The SecurityAction.RequestMinimum security action indicates that this is the minimum permission required for the target assembly to be able to execute.

[assembly:EnvironmentPermissionAttribute(SecurityAction.RequestMinimum, Read="COMPUTERNAME;USERNAME;USERDOMAIN")]

The following example shows how to demand that the calling code has unrestricted access to all environment variables. Demands are typically made in managed libraries to protect methods or classes from malicious code.

[EnvironmentPermissionAttribute(SecurityAction.Demand, Unrestricted=true)]

Requirements

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