Export (0) Print
Expand All
Expand Minimize

SecurityAction Enumeration

Specifies the security actions that can be performed using declarative security.

Namespace: System.Security.Permissions
Assembly: mscorlib (in mscorlib.dll)

[SerializableAttribute] 
[ComVisibleAttribute(true)] 
public enum class SecurityAction
/** @attribute SerializableAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
public enum SecurityAction
SerializableAttribute 
ComVisibleAttribute(true) 
public enum SecurityAction

 Member nameDescription
AssertThe calling code can access the resource identified by the current permission object, even if callers higher in the stack have not been granted permission to access the resource (see Using the Assert Method). 
DemandAll callers higher in the call stack are required to have been granted the permission specified by the current permission object (see Security Demands). 
DenyThe ability to access the resource specified by the current permission object is denied to callers, even if they have been granted permission to access it (see Using the Deny Method). 
InheritanceDemandThe derived class inheriting the class or overriding a method is required to have been granted the specified permission. 
Supported by the .NET Compact FrameworkLinkDemandThe immediate caller is required to have been granted the specified permission. 

For more information on declarative security and link demands, see Declarative Security Used with Class and Member Scope.

PermitOnlyOnly the resources specified by this permission object can be accessed, even if the code has been granted permission to access other resources (see Using the PermitOnly Method). 
RequestMinimumThe request for the minimum permissions required for code to run. This action can only be used within the scope of the assembly. 
RequestOptionalThe request for additional permissions that are optional (not required to run). This request implicitly refuses all other permissions not specifically requested. This action can only be used within the scope of the assembly.  
RequestRefuseThe request that permissions that might be misused will not be granted to the calling code. This action can only be used within the scope of the assembly. 

The following table describes the time that each of the security actions takes place and the targets that each supports.

Declaration of security action

Time of action

Targets supported

LinkDemand

Just-in-time compilation

Class, Method

InheritanceDemand

Load time

Class, Method

Demand

Run time

Class, Method

Assert

Run time

Class, Method

Deny

Run time

Class, Method

PermitOnly

Run time

Class, Method

RequestMinimum

Grant time

Assembly

RequestOptional

Grant time

Assembly

RequestRefuse

Grant time

Assembly

For additional information about attribute targets, see Attribute.

This example shows how to tell the CLR that code in this assembly requires the IsolatedStoragePermission and also demonstrates how to write and read from isolated storage.

using namespace System;
using namespace System::Security;
using namespace System::Security::Permissions;
using namespace System::IO::IsolatedStorage;
using namespace System::IO;

// Notify the CLR to grant this assembly the IsolatedStorage-
// FilePermission. This allows the assembly to work with storage
// files that are isolated by user and assembly.
[assembly: IsolatedStorageFilePermission(
    SecurityAction::RequestMinimum, UsageAllowed =
    IsolatedStorageContainment::AssemblyIsolationByUser)];
int main()
{
    try
    {
        // Attempt to create a storage file that is isolated by
        // user and assembly. IsolatedStorageFilePermission
        // granted to the attribute at the top of this file
        // allows CLR to load this assembly and execution of this
        // statement.
        Stream^ fileCreateStream = gcnew
            IsolatedStorageFileStream(
            "AssemblyData",
            FileMode::Create,
            IsolatedStorageFile::GetUserStoreForAssembly());

        StreamWriter^ streamWriter = gcnew StreamWriter(
            fileCreateStream);
        try
        {
            // Write some data out to the isolated file.

            streamWriter->Write("This is some test data.");
            streamWriter->Close();	
        }
        finally
        {
            delete fileCreateStream;
            delete streamWriter;
        } 
    }
    catch (IOException^ ex)
    {
        Console::WriteLine(ex->Message);
    }

    try
    {
        Stream^ fileOpenStream =
            gcnew IsolatedStorageFileStream(
            "AssemblyData",
            FileMode::Open,
            IsolatedStorageFile::GetUserStoreForAssembly());
        // Attempt to open the file that was previously created.

        StreamReader^ streamReader = gcnew StreamReader(
            fileOpenStream);
        try
        { 
            // Read the data from the file and display it.

            Console::WriteLine(streamReader->ReadLine());
            streamReader->Close();
        }
        finally
        {
            delete fileOpenStream;
            delete streamReader;
        }
    }
    catch (FileNotFoundException^ ex)
    {
        Console::WriteLine(ex->Message);
    }
    catch (IOException^ ex)
    {
        Console::WriteLine(ex->Message);
    }
}

// This code produces the following output.
//
//  This is some test data.

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

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

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2014 Microsoft