CodeAccessSecurityAttribute Classe
Definição
Cuidado
Code Access Security is not supported or honored by the runtime.
Cuidado
CAS support is not available with Silverlight applications.
Especifica a classe de atributo base para a segurança de acesso do código.Specifies the base attribute class for code access security.
public ref class CodeAccessSecurityAttribute abstract : System::Security::Permissions::SecurityAttribute
[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Constructor | System.AttributeTargets.Method | System.AttributeTargets.Struct, AllowMultiple=true, Inherited=false)]
public abstract class CodeAccessSecurityAttribute : System.Security.Permissions.SecurityAttribute
[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Constructor | System.AttributeTargets.Method | System.AttributeTargets.Struct, AllowMultiple=true, Inherited=false)]
[System.Obsolete("Code Access Security is not supported or honored by the runtime.", DiagnosticId="SYSLIB0003", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
public abstract class CodeAccessSecurityAttribute : System.Security.Permissions.SecurityAttribute
[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Constructor | System.AttributeTargets.Method | System.AttributeTargets.Struct, AllowMultiple=true, Inherited=false)]
[System.Serializable]
public abstract class CodeAccessSecurityAttribute : System.Security.Permissions.SecurityAttribute
[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Constructor | System.AttributeTargets.Method | System.AttributeTargets.Struct, AllowMultiple=true, Inherited=false)]
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
public abstract class CodeAccessSecurityAttribute : System.Security.Permissions.SecurityAttribute
[System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Constructor | System.AttributeTargets.Method | System.AttributeTargets.Struct, AllowMultiple=true, Inherited=false)]
[System.Serializable]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Obsolete("CAS support is not available with Silverlight applications.")]
public abstract class CodeAccessSecurityAttribute : System.Security.Permissions.SecurityAttribute
[<System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Constructor | System.AttributeTargets.Method | System.AttributeTargets.Struct, AllowMultiple=true, Inherited=false)>]
type CodeAccessSecurityAttribute = class
inherit SecurityAttribute
[<System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Constructor | System.AttributeTargets.Method | System.AttributeTargets.Struct, AllowMultiple=true, Inherited=false)>]
[<System.Obsolete("Code Access Security is not supported or honored by the runtime.", DiagnosticId="SYSLIB0003", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
type CodeAccessSecurityAttribute = class
inherit SecurityAttribute
[<System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Constructor | System.AttributeTargets.Method | System.AttributeTargets.Struct, AllowMultiple=true, Inherited=false)>]
[<System.Serializable>]
type CodeAccessSecurityAttribute = class
inherit SecurityAttribute
[<System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Constructor | System.AttributeTargets.Method | System.AttributeTargets.Struct, AllowMultiple=true, Inherited=false)>]
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
type CodeAccessSecurityAttribute = class
inherit SecurityAttribute
[<System.AttributeUsage(System.AttributeTargets.Assembly | System.AttributeTargets.Class | System.AttributeTargets.Constructor | System.AttributeTargets.Method | System.AttributeTargets.Struct, AllowMultiple=true, Inherited=false)>]
[<System.Serializable>]
[<System.Runtime.InteropServices.ComVisible(true)>]
[<System.Obsolete("CAS support is not available with Silverlight applications.")>]
type CodeAccessSecurityAttribute = class
inherit SecurityAttribute
Public MustInherit Class CodeAccessSecurityAttribute
Inherits SecurityAttribute
- Herança
- Derivado
- Atributos
Exemplos
O exemplo a seguir mostra um atributo de permissão derivado da CodeAccessSecurityAttribute classe.The following example shows a permission attribute derived from the CodeAccessSecurityAttribute class.
using namespace System;
using namespace System::IO;
using namespace System::Runtime::Remoting;
using namespace System::Security;
using namespace System::Security::Permissions;
using namespace System::Reflection;
using namespace MyPermission;
// Use the command line option '/keyfile' or appropriate project settings to sign this assembly.
[assembly:System::Security::AllowPartiallyTrustedCallersAttribute];
[AttributeUsage(AttributeTargets::Method|AttributeTargets::Constructor|AttributeTargets::Class|AttributeTargets::Struct|AttributeTargets::Assembly,AllowMultiple=true,Inherited=false)]
[Serializable]
public ref class NameIdPermissionAttribute: public CodeAccessSecurityAttribute
{
private:
String^ m_Name;
bool m_unrestricted;
public:
NameIdPermissionAttribute( SecurityAction action )
: CodeAccessSecurityAttribute( action )
{
m_Name = nullptr;
m_unrestricted = false;
}
property String^ Name
{
String^ get()
{
return m_Name;
}
void set( String^ value )
{
m_Name = value;
}
}
virtual IPermission^ CreatePermission() override
{
if ( m_unrestricted )
{
throw gcnew ArgumentException( "Unrestricted permissions not allowed in identity permissions." );
}
else
{
if ( m_Name == nullptr )
return gcnew NameIdPermission( PermissionState::None );
return gcnew NameIdPermission( m_Name );
}
}
};
using System;
using System.IO;
using System.Runtime.Remoting;
using System.Security;
using System.Security.Permissions;
using System.Reflection;
using MyPermission;
// Use the command line option '/keyfile' or appropriate project settings to sign this assembly.
[assembly: System.Security.AllowPartiallyTrustedCallersAttribute ()]
namespace MyPermissionAttribute
{
[AttributeUsage (AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Assembly, AllowMultiple = true, Inherited = false)]
[Serializable]
sealed public class NameIdPermissionAttribute : CodeAccessSecurityAttribute
{
private String m_Name = null;
private bool m_unrestricted = false;
public NameIdPermissionAttribute (SecurityAction action): base( action )
{
}
public String Name
{
get { return m_Name; }
set { m_Name = value; }
}
public override IPermission CreatePermission ()
{
if (m_unrestricted)
{
throw new ArgumentException ("Unrestricted permissions not allowed in identity permissions.");
}
else
{
if (m_Name == null)
return new NameIdPermission (PermissionState.None);
return new NameIdPermission (m_Name);
}
}
}
}
Imports System.IO
Imports System.Runtime.Remoting
Imports System.Security
Imports System.Security.Permissions
Imports System.Reflection
Imports MyPermission
' Use the command line option '/keyfile' or appropriate project settings to sign this assembly.
<Assembly: System.Security.AllowPartiallyTrustedCallersAttribute()>
Namespace MyPermissionAttribute
<AttributeUsage(AttributeTargets.All, AllowMultiple:=True, Inherited:=False)> Public NotInheritable Class NameIdPermissionAttribute
Inherits CodeAccessSecurityAttribute
Private m_Name As String = Nothing
Private m_unrestricted As Boolean = False
Public Sub New(ByVal action As SecurityAction)
MyBase.New(action)
End Sub
Public Property Name() As String
Get
Return m_name
End Get
Set(ByVal Value As String)
m_name = Value
End Set
End Property
Public Overrides Function CreatePermission() As IPermission
If m_unrestricted Then
Throw New ArgumentException("Unrestricted permissions not allowed in identity permissions.")
Else
If m_name Is Nothing Then
Return New NameIdPermission(PermissionState.None)
End If
Return New NameIdPermission(m_name)
End If
End Function 'CreatePermission
End Class
End Namespace
Comentários
Importante
Não há mais suporte para código parcialmente confiável.Partially trusted code is no longer supported. Esse atributo não tem nenhum efeito no .NET Core.This attribute has no effect in .NET Core.
Essa classe de atributo associa um SecurityAction , por exemplo, Demand
, a um atributo de segurança personalizado.This attribute class associates a SecurityAction, for example, Demand
, with a custom security attribute.
Os tipos que derivam de CodeAccessSecurityAttribute são usados para ajudar a restringir o acesso a recursos ou operações protegíveis.The types that derive from CodeAccessSecurityAttribute are used to help restrict access to resources or securable operations.
As informações de segurança declaradas por um atributo de segurança são armazenadas nos metadados do destino do atributo e são acessadas pelo sistema em tempo de execução.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. Os atributos de segurança são usados apenas para segurança declarativa.Security attributes are used only for declarative security. Use a classe de permissão correspondente derivada de CodeAccessPermission para segurança imperativa.Use the corresponding permission class derived from CodeAccessPermission for imperative security.
Notas aos Implementadores
Todos os atributos de permissão derivados desta classe devem ter apenas um único Construtor que usa um SecurityAction como seu único parâmetro.All permission attributes derived from this class must have only a single constructor that takes a SecurityAction as its only parameter.
Construtores
CodeAccessSecurityAttribute(SecurityAction) |
Inicializa uma nova instância de CodeAccessSecurityAttribute com o SecurityActionespecificado.Initializes a new instance of CodeAccessSecurityAttribute with the specified SecurityAction. |
Propriedades
Action |
Obtém ou define uma ação de segurança.Gets or sets a security action. (Herdado de SecurityAttribute) |
TypeId |
Quando implementado em uma classe derivada, obtém um identificador exclusivo para este Attribute.When implemented in a derived class, gets a unique identifier for this Attribute. (Herdado de Attribute) |
Unrestricted |
Obtém ou define um valor que indica se a permissão total (irrestrita) para o recurso protegido pelo atributo é declarada.Gets or sets a value indicating whether full (unrestricted) permission to the resource protected by the attribute is declared. (Herdado de SecurityAttribute) |
Métodos
CreatePermission() |
Quando substituído em uma classe derivada, cria um objeto de permissão que pode ser serializado em formato binário e persistentemente armazenado juntamente com o SecurityAction nos metadados do assembly.When overridden in a derived class, creates a permission object that can then be serialized into binary form and persistently stored along with the SecurityAction in an assembly's metadata. (Herdado de SecurityAttribute) |
Equals(Object) |
Retorna um valor que indica se essa instância é igual a um objeto especificado.Returns a value that indicates whether this instance is equal to a specified object. (Herdado de Attribute) |
GetHashCode() |
Retorna o código hash para a instância.Returns the hash code for this instance. (Herdado de Attribute) |
GetType() |
Obtém o Type da instância atual.Gets the Type of the current instance. (Herdado de Object) |
IsDefaultAttribute() |
Quando substituído em uma classe derivada, indica se o valor dessa instância é o valor padrão para a classe derivada.When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class. (Herdado de Attribute) |
Match(Object) |
Quando substituído em uma classe derivada, retorna um valor que indica se essa instância é igual a um objeto especificado.When overridden in a derived class, returns a value that indicates whether this instance equals a specified object. (Herdado de Attribute) |
MemberwiseClone() |
Cria uma cópia superficial do Object atual.Creates a shallow copy of the current Object. (Herdado de Object) |
ToString() |
Retorna uma cadeia de caracteres que representa o objeto atual.Returns a string that represents the current object. (Herdado de Object) |
Implantações explícitas de interface
_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) |
Mapeia um conjunto de nomes para um conjunto correspondente de identificadores de expedição.Maps a set of names to a corresponding set of dispatch identifiers. (Herdado de Attribute) |
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) |
Recupera as informações de tipo para um objeto, que pode ser usado para obter as informações de tipo para uma interface.Retrieves the type information for an object, which can be used to get the type information for an interface. (Herdado de Attribute) |
_Attribute.GetTypeInfoCount(UInt32) |
Retorna o número de interfaces de informações do tipo que um objeto fornece (0 ou 1).Retrieves the number of type information interfaces that an object provides (either 0 or 1). (Herdado de Attribute) |
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) |
Fornece acesso a propriedades e métodos expostos por um objeto.Provides access to properties and methods exposed by an object. (Herdado de Attribute) |