Freigeben über


IsolatedStorageFilePermissionAttribute-Klasse

Lässt zu, dass Sicherheitsaktionen für IsolatedStorageFilePermission mithilfe der Deklarationssicherheit auf Code angewendet werden. Diese Klasse kann nicht vererbt werden.

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

Syntax

'Declaration
<SerializableAttribute> _
<ComVisibleAttribute(True)> _
<AttributeUsageAttribute(AttributeTargets.Assembly Or AttributeTargets.Class Or AttributeTargets.Struct Or AttributeTargets.Constructor Or AttributeTargets.Method, AllowMultiple:=True, Inherited:=False)> _
Public NotInheritable Class IsolatedStorageFilePermissionAttribute
    Inherits IsolatedStoragePermissionAttribute
'Usage
Dim instance As IsolatedStorageFilePermissionAttribute
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
[AttributeUsageAttribute(AttributeTargets.Assembly|AttributeTargets.Class|AttributeTargets.Struct|AttributeTargets.Constructor|AttributeTargets.Method, AllowMultiple=true, Inherited=false)] 
public sealed class IsolatedStorageFilePermissionAttribute : IsolatedStoragePermissionAttribute
[SerializableAttribute] 
[ComVisibleAttribute(true)] 
[AttributeUsageAttribute(AttributeTargets::Assembly|AttributeTargets::Class|AttributeTargets::Struct|AttributeTargets::Constructor|AttributeTargets::Method, AllowMultiple=true, Inherited=false)] 
public ref class IsolatedStorageFilePermissionAttribute sealed : public IsolatedStoragePermissionAttribute
/** @attribute SerializableAttribute() */ 
/** @attribute ComVisibleAttribute(true) */ 
/** @attribute AttributeUsageAttribute(AttributeTargets.Assembly|AttributeTargets.Class|AttributeTargets.Struct|AttributeTargets.Constructor|AttributeTargets.Method, AllowMultiple=true, Inherited=false) */ 
public final class IsolatedStorageFilePermissionAttribute extends IsolatedStoragePermissionAttribute
SerializableAttribute 
ComVisibleAttribute(true) 
AttributeUsageAttribute(AttributeTargets.Assembly|AttributeTargets.Class|AttributeTargets.Struct|AttributeTargets.Constructor|AttributeTargets.Method, AllowMultiple=true, Inherited=false) 
public final class IsolatedStorageFilePermissionAttribute extends IsolatedStoragePermissionAttribute

Hinweise

Der zulässige Gültigkeitsbereich der Deklaration hängt von der verwendeten SecurityAction ab.

Die von einem Sicherheitsattribut deklarierten Sicherheitsinformationen werden in den Metadaten des Attributzieles gespeichert. Das System greift auf diese Sicherheitsinformationen zur Laufzeit zu. Sicherheitsattribute werden ausschließlich für deklarative Sicherheit verwendet. Verwenden Sie für imperative Sicherheit die entsprechende Berechtigungsklasse.

Beispiel

Im folgenden Beispiel eines deklarativen Attributs wird eine ordnungsgemäße Anforderung von IsolatedStorageFilePermission dargestellt und mitgeteilt, dass Sie zum Ausführen des Codes mindestens über diese Berechtigung und ein maximales Benutzerkontingent von 5 MB verfügen müssen.

<Assembly: IsolatedStorageFilePermissionAttribute( _
SecurityAction.RequestMinimum, UserQuota := 5242880)>
'In Visual Basic, you must specify that you are using the assembly scope when making a request.
[assembly:IsolatedStorageFilePermissionAttribute(
SecurityAction.RequestMinimum, UserQuota=5242880)]
//In C#, you must specify that you are using the assembly scope when making a request.
[assembly:IsolatedStorageFilePermissionAttribute(
SecurityAction::RequestMinimum,UserQuota=5242880)];
//In C++, you must specify that you are using the assembly scope when making a request.
/** @assembly IsolatedStorageFilePermissionAttribute(SecurityAction.
    RequestMinimum, UserQuota = 5242880)
 */
// In VJ#, you must specify that you are using the assembly scope when making
// a request.

Im folgenden Beispiel wird veranschaulicht, wie gefordert wird, dass der Aufrufcode zur Verknüpfungszeit über eine uneingeschränkte IsolatedStorageFilePermission verfügt. Anforderungen werden i. d. R. in verwalteten Bibliotheken (DLLs) vorgenommen, um Methoden und Klassen vor möglicherweise böswilligem Code zu schützen.

<IsolatedStorageFilePermissionAttribute( _
 SecurityAction.Demand, Unrestricted := True)> _
 Public Class SampleClass
[IsolatedStorageFilePermissionAttribute(SecurityAction.Demand,
Unrestricted=true)]
[IsolatedStorageFilePermissionAttribute(SecurityAction::Demand,
Unrestricted=true)]
/** @attribute IsolatedStorageFilePermissionAttribute(SecurityAction.Demand, 
    Unrestricted = true)
 */

In diesem Beispiel wird veranschaulicht, wie der CLR mitgeteilt wird, dass IsolatedStoragePermission für Code in dieser Assembly erforderlich ist, und wie der isolierte Speicher geschrieben und gelesen wird.

using System;
using System.Security.Permissions;
using System.IO.IsolatedStorage;
using System.IO;

// Notify the CLR to grant this assembly the IsolatedStorageFilePermission. 
// This allows the assembly to work with storage files that are isolated 
// by user and assembly.
[assembly: IsolatedStorageFilePermission(SecurityAction.RequestMinimum, UsageAllowed = IsolatedStorageContainment.AssemblyIsolationByUser)]

public sealed class App
{
    static void Main()
    {
        // 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.
        using (Stream s = new IsolatedStorageFileStream("AssemblyData", FileMode.Create, IsolatedStorageFile.GetUserStoreForAssembly()))
        {
         
             // Write some data out to the isolated file.
             using (StreamWriter sw = new StreamWriter(s))
             {
                sw.Write("This is some test data.");
             }
        }

        // Attempt to open the file that was previously created.
        using (Stream s = new IsolatedStorageFileStream("AssemblyData", FileMode.Open, IsolatedStorageFile.GetUserStoreForAssembly()))
        {
             // Read the data from the file and display it.
             using (StreamReader sr = new StreamReader(s))
             {
                 Console.WriteLine(sr.ReadLine());
             }
        }
    }
}

// This code produces the following output.
//
//  Some test data.
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.

Vererbungshierarchie

System.Object
   System.Attribute
     System.Security.Permissions.SecurityAttribute
       System.Security.Permissions.CodeAccessSecurityAttribute
         System.Security.Permissions.IsolatedStoragePermissionAttribute
          System.Security.Permissions.IsolatedStorageFilePermissionAttribute

Threadsicherheit

Alle öffentlichen statischen (Shared in Visual Basic) Member dieses Typs sind threadsicher. Bei Instanzmembern ist die Threadsicherheit nicht gewährleistet.

Plattformen

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

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

Siehe auch

Referenz

IsolatedStorageFilePermissionAttribute-Member
System.Security.Permissions-Namespace
IsolatedStorageFilePermission-Klasse
IsolatedStoragePermission
IsolatedStoragePermissionAttribute
IsolatedStorageContainment-Enumeration

Weitere Ressourcen

Erweitern von Metadaten mithilfe von Attributen