SecurityAction Sabit listesi

Tanım

Dikkat

Code Access Security is not supported or honored by the runtime.

Dikkat

CAS support is not available with Silverlight applications.

Bildirim temelli güvenlik kullanılarak gerçekleştirilebilecek güvenlik eylemlerini belirtir.

public enum class SecurityAction
[System.Obsolete("Code Access Security is not supported or honored by the runtime.", DiagnosticId="SYSLIB0003", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
public enum SecurityAction
public enum SecurityAction
[System.Serializable]
public enum SecurityAction
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public enum SecurityAction
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Obsolete("CAS support is not available with Silverlight applications.")]
public enum SecurityAction
[<System.Obsolete("Code Access Security is not supported or honored by the runtime.", DiagnosticId="SYSLIB0003", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
type SecurityAction = 
type SecurityAction = 
[<System.Serializable>]
type SecurityAction = 
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type SecurityAction = 
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
[<System.Obsolete("CAS support is not available with Silverlight applications.")>]
type SecurityAction = 
Public Enum SecurityAction
Devralma
SecurityAction
Öznitelikler

Alanlar

Assert 3

Yığında daha yüksek arayanlara kaynağa erişim izni verilmemiş olsa bile, çağıran kod geçerli izin nesnesi tarafından tanımlanan kaynağa erişebilir (bkz. Assert Yöntemini Kullanma).

Demand 2

Çağrı yığınında daha yüksek olan tüm çağıranlara geçerli izin nesnesi tarafından belirtilen iznin verilmiş olması gerekir.

Deny 4

Geçerli izin nesnesi tarafından belirtilen kaynağa erişim izni verilmiş olsa bile arayanlara erişim engellendi (bkz . Reddetme Yöntemini Kullanma).

InheritanceDemand 7

Sınıfı devralan veya bir yöntemi geçersiz kılan türetilmiş sınıfın belirtilen izinlere sahip olması gerekir.

LinkDemand 6

Hemen çağıranın belirtilen izinlere sahip olması gerekir. .NET Framework 4'te kullanmayın. Tam güven için, bunun yerine kullanın SecurityCriticalAttribute ; kısmi güven için kullanın Demand.

PermitOnly 5

Koda diğer kaynaklara erişim izni verilmiş olsa bile yalnızca bu izin nesnesi tarafından belirtilen kaynaklara erişilebilir.

RequestMinimum 8

Kodun çalışması için gereken en düşük izinlere yönelik istek. Bu eylem yalnızca derleme kapsamında kullanılabilir.

RequestOptional 9

İsteğe bağlı ek izinler isteği (çalıştırmak için gerekli değildir). Bu istek, özellikle istenmeyen diğer tüm izinleri örtük olarak reddeder. Bu eylem yalnızca derleme kapsamında kullanılabilir.

RequestRefuse 10

Kötüye kullanılabilecek izinlerin çağrı koduna verilmemesi isteği. Bu eylem yalnızca derleme kapsamında kullanılabilir.

Örnekler

Bu örnek, çağrılan yöntemlerdeki kodun yalnızca IsolatedStoragePermissionöğesine sahip olduğunu CLR'ye bildirmeyi ve ayrıca yalıtılmış depolamadan yazma ve okuma işlemini gösterir.

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


static void WriteIsolatedStorage()
{
    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);
    }
}
// Notify the CLR to only grant IsolatedStorageFilePermission to called methods. 
// This restricts the called methods to working only with storage files that are isolated 
// by user and assembly.
[IsolatedStorageFilePermission(SecurityAction::PermitOnly, UsageAllowed = IsolatedStorageContainment::AssemblyIsolationByUser)]
int main()
{
    WriteIsolatedStorage();
}

// This code produces the following output.
//
//  This is some test data.
using System;
using System.Security.Permissions;
using System.IO.IsolatedStorage;
using System.IO;

// Notify the CLR to only grant IsolatedStorageFilePermission to called methods.
// This restricts the called methods to working only with storage files that are isolated
// by user and assembly.
[IsolatedStorageFilePermission(SecurityAction.PermitOnly, UsageAllowed = IsolatedStorageContainment.AssemblyIsolationByUser)]
public sealed class App
{
    static void Main()
    {
        WriteIsolatedStorage();
    }
    private static void WriteIsolatedStorage()
    {
        // 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.
Option Strict On
Imports System.Security.Permissions
Imports System.IO.IsolatedStorage
Imports System.IO


' Notify the CLR to only grant IsolatedStorageFilePermission to called methods. 
' This restricts the called methods to working only with storage files that are isolated 
' by user and assembly.
<IsolatedStorageFilePermission(SecurityAction.PermitOnly, UsageAllowed:=IsolatedStorageContainment.AssemblyIsolationByUser)> _
Public NotInheritable Class App

    Shared Sub Main()
        WriteIsolatedStorage()
    End Sub
    Shared Sub WriteIsolatedStorage()
        ' 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.
        Dim s As New IsolatedStorageFileStream("AssemblyData", FileMode.Create, IsolatedStorageFile.GetUserStoreForAssembly())
        Try

            ' Write some data out to the isolated file.
            Dim sw As New StreamWriter(s)
            Try
                sw.Write("This is some test data.")
            Finally
                sw.Dispose()
            End Try
        Finally
            s.Dispose()
        End Try

        ' Attempt to open the file that was previously created.
        Dim t As New IsolatedStorageFileStream("AssemblyData", FileMode.Open, IsolatedStorageFile.GetUserStoreForAssembly())
        Try
            ' Read the data from the file and display it.
            Dim sr As New StreamReader(t)
            Try
                Console.WriteLine(sr.ReadLine())
            Finally
                sr.Dispose()
            End Try
        Finally
            t.Dispose()
        End Try

    End Sub
End Class

' This code produces the following output.
'
'  Some test data.

Açıklamalar

Dikkat

Kod Erişim Güvenliği (CAS), .NET Framework ve .NET'in tüm sürümlerinde kullanım dışı bırakılmıştır. .NET'in son sürümleri CAS ek açıklamalarını dikkate almaz ve CAS ile ilgili API'ler kullanılıyorsa hata üretir. Geliştiriciler, güvenlik görevlerini yerine getirmek için alternatif yöntemler aramalıdır.

Aşağıdaki tabloda, her bir güvenlik eyleminin gerçekleştiği saat ve desteklediği hedefler açıklanmaktadır.

Önemli

.NET Framework 4'te Deny, RequestMinimum, RequestOptional ve RequestRefuse izin isteklerinin zorlanması için çalışma zamanı desteği kaldırılmıştır. Bu istekler, .NET Framework 4 veya üzerini temel alan kodda kullanılmamalıdır. Bu ve diğer değişiklikler hakkında daha fazla bilgi için bkz . Güvenlik Değişiklikleri.

.NET Framework 4'te kullanmamalısınızLinkDemand. Bunun yerine, SecurityCriticalAttribute kullanımı tam olarak güvenilen uygulamalarla kısıtlamak için veya kısmen güvenilen arayanları kısıtlamak için kullanın Demand .

Güvenlik eylemi bildirimi Eylem zamanı Desteklenen hedefler
LinkDemand(.NET Framework 4'te kullanmayın) Tam zamanında derleme Sınıf, yöntem
InheritanceDemand Yükleme süresi Sınıf, yöntem
Demand Çalışma zamanı Sınıf, yöntem
Assert Çalışma zamanı Sınıf, yöntem
Deny(.NET Framework 4'te kullanımdan kaldırıldı) Çalışma zamanı Sınıf, yöntem
PermitOnly Çalışma zamanı Sınıf, yöntem
RequestMinimum(.NET Framework 4'te kullanımdan kaldırıldı) Zaman ver Bütünleştirilmiş Kod
RequestOptional(.NET Framework 4'te kullanımdan kaldırıldı) Zaman ver Bütünleştirilmiş Kod
RequestRefuse(.NET Framework 4'te kullanımdan kaldırıldı) Zaman ver Bütünleştirilmiş Kod

Öznitelik hedefleri hakkında ek bilgi için bkz Attribute. .

Şunlara uygulanır