XmlSecureResolver Construtores

Definição

Inicializa uma nova instância da classe XmlSecureResolver.Initializes a new instance of the XmlSecureResolver class.

Sobrecargas

XmlSecureResolver(XmlResolver, PermissionSet)

Inicializa uma nova instância da classe XmlSecureResolver com o XmlResolver e PermissionSet especificados.Initializes a new instance of the XmlSecureResolver class with the XmlResolver and PermissionSet specified.

XmlSecureResolver(XmlResolver, Evidence)

Inicializa uma nova instância da classe XmlSecureResolver com o XmlResolver e Evidence especificados.Initializes a new instance of the XmlSecureResolver class with the XmlResolver and Evidence specified.

XmlSecureResolver(XmlResolver, String)

Inicializa uma nova instância da classe XmlSecureResolver com o XmlResolver e a URL fornecida.Initializes a new instance of the XmlSecureResolver class with the XmlResolver and URL provided.

Comentários

Os três construtores fornecem três tipos de restrições de acesso:The three constructors provide three types of access restrictions:

Consulte os tópicos de referência do construtor para obter exemplos desses tipos de restrições.See the constructor reference topics for examples of these types of restrictions.

XmlSecureResolver(XmlResolver, PermissionSet)

Inicializa uma nova instância da classe XmlSecureResolver com o XmlResolver e PermissionSet especificados.Initializes a new instance of the XmlSecureResolver class with the XmlResolver and PermissionSet specified.

public:
 XmlSecureResolver(System::Xml::XmlResolver ^ resolver, System::Security::PermissionSet ^ permissionSet);
public XmlSecureResolver (System.Xml.XmlResolver resolver, System.Security.PermissionSet permissionSet);
new System.Xml.XmlSecureResolver : System.Xml.XmlResolver * System.Security.PermissionSet -> System.Xml.XmlSecureResolver
Public Sub New (resolver As XmlResolver, permissionSet As PermissionSet)

Parâmetros

resolver
XmlResolver

O resolvedor XML que é encapsulado pelo XmlSecureResolver.The XML resolver that is wrapped by the XmlSecureResolver.

permissionSet
PermissionSet

O conjunto de permissões a ser aplicado ao XmlResolver subjacente.The permission set to apply to the underlying XmlResolver. O XmlSecureResolver chama o método PermitOnly() na permissão definida antes de chamar o método GetEntity(Uri, String, Type) no resolvedor XML subjacente.The XmlSecureResolver calls the PermitOnly() method on the permission set before calling the GetEntity(Uri, String, Type) method on the underlying XML resolver.

Exemplos

O exemplo a seguir constrói um XmlSecureResolver objeto usando um conjunto de permissões personalizado.The following example constructs an XmlSecureResolver object by using a customized permission set.

Object^ GetFile( String^ fileURL, XmlResolver^ resolver )
{
   // Generate the default PermissionSet using the file URL.
   Evidence^ evidence = XmlSecureResolver::CreateEvidenceForUrl( fileURL );
   PermissionSet^ myPermissions = SecurityManager::ResolvePolicy( evidence );
   
   // Modify the PermissionSet to only allow access to http://www.contoso.com.
   // Create a WebPermission which only allows access to http://www.contoso.com.
   WebPermission^ myWebPermission = gcnew WebPermission(
      NetworkAccess::Connect,"http://www.contoso.com" );
   // Replace the existing WebPermission in myPermissions with the updated WebPermission.
   myPermissions->SetPermission( myWebPermission );
   
   // Use the modified PermissionSet to construct the XmlSecureResolver.
   XmlSecureResolver^ sResolver = gcnew XmlSecureResolver( resolver,myPermissions );
   
   // Get the object.
   Uri^ fullUri = sResolver->ResolveUri( nullptr, fileURL );
   return sResolver->GetEntity( fullUri, nullptr, nullptr );
}

public static Object GetFile (String fileURL, XmlResolver resolver) {

  // Generate the default PermissionSet using the file URL.
  Evidence evidence = XmlSecureResolver.CreateEvidenceForUrl(fileURL);
  PermissionSet myPermissions = SecurityManager.ResolvePolicy(evidence);

  // Modify the PermissionSet to only allow access to http://www.contoso.com.
  // Create a WebPermission which only allows access to http://www.contoso.com.
  WebPermission myWebPermission = new WebPermission(NetworkAccess.Connect, "http://www.contoso.com");
  // Replace the existing WebPermission in myPermissions with the updated WebPermission.
  myPermissions.SetPermission(myWebPermission);

  // Use the modified PermissionSet to construct the XmlSecureResolver.
  XmlSecureResolver sResolver = new XmlSecureResolver(resolver, myPermissions);

  // Get the object.
  Uri fullUri = sResolver.ResolveUri(null, fileURL);
  return sResolver.GetEntity(fullUri, null, null);
}

public shared function GetFile (fileURL as String , resolver as XmlResolver) as Object
 
  '  Generate the default PermissionSet using the file URL.
  Dim evidence as Evidence = XmlSecureResolver.CreateEvidenceForUrl(fileURL)
  Dim myPermissions as PermissionSet = SecurityManager.ResolvePolicy(evidence)

  '  Modify the PermissionSet to only allow access to http://www.contoso.com.
  '  Create a WebPermission that only allows access to http://www.contoso.com.
  Dim myWebPermission as WebPermission = new WebPermission(NetworkAccess.Connect, "http://www.contoso.com")
  '  Replace the existing WebPermission in myPermissions with the updated WebPermission.
  myPermissions.SetPermission(myWebPermission)

  '  Use the modified PermissionSet to construct the XmlSecureResolver.
  Dim sResolver as XmlSecureResolver = new XmlSecureResolver(resolver, myPermissions)

  '  Get the object.
  Dim fullUri as Uri = sResolver.ResolveUri(nothing, fileURL)
  return sResolver.GetEntity(fullUri, nothing, nothing)
end function 

Confira também

Aplica-se a

XmlSecureResolver(XmlResolver, Evidence)

Inicializa uma nova instância da classe XmlSecureResolver com o XmlResolver e Evidence especificados.Initializes a new instance of the XmlSecureResolver class with the XmlResolver and Evidence specified.

public:
 XmlSecureResolver(System::Xml::XmlResolver ^ resolver, System::Security::Policy::Evidence ^ evidence);
public XmlSecureResolver (System.Xml.XmlResolver resolver, System.Security.Policy.Evidence evidence);
new System.Xml.XmlSecureResolver : System.Xml.XmlResolver * System.Security.Policy.Evidence -> System.Xml.XmlSecureResolver
Public Sub New (resolver As XmlResolver, evidence As Evidence)

Parâmetros

resolver
XmlResolver

O resolvedor XML que é encapsulado pelo XmlSecureResolver.The XML resolver that is wrapped by the XmlSecureResolver.

evidence
Evidence

A evidência a ser usada para criar o PermissionSet que será aplicado ao XmlResolver subjacente.The evidence used to create the PermissionSet that will be applied to the underlying XmlResolver. O XmlSecureResolver chama o método PermitOnly() criado PermissionSet antes de chamar GetEntity(Uri, String, Type) no XmlResolver subjacente.The XmlSecureResolver calls the PermitOnly() method on the created PermissionSet before calling GetEntity(Uri, String, Type) on the underlying XmlResolver.

Comentários

Aqui estão alguns cenários possíveis e o tipo de evidência a ser fornecido para cada cenário:Here are some possible scenarios and the type of evidence to provide for each scenario:

  • Se você estiver trabalhando em um ambiente totalmente confiável, use seu assembly para criar a evidência:If you are working in a fully trusted environment, use your assembly to create the evidence:

    Evidence myEvidence = this.GetType().Assembly.Evidence;
    XmlSecureResolver myResolver;
    myResolver = new XmlSecureResolver(new XmlUrlResolver(), myEvidence);
    
    Dim myEvidence As Evidence = Me.GetType().Assembly.Evidence
    Dim myResolver As XmlSecureResolver
    myResolver = New XmlSecureResolver(New XmlUrlResolver(), myEvidence)
    
  • Se você estiver trabalhando em um ambiente semiconfiável, terá código ou dados provenientes de uma fonte externa e souber a origem da origem externa e ter um URI verificável, usar o URI para criar a evidência:If you are working in a semi-trusted environment, you have code or data coming from an outside source, and you know the origin of the outside source and have a verifiable URI, use the URI to create the evidence:

    
    Evidence myEvidence = XmlSecureResolver.CreateEvidenceForUrl(sourceURI);
    XmlSecureResolver myResolver = new XmlSecureResolver(new XmlUrlResolver(), myEvidence);
    
    Dim myEvidence As Evidence = XmlSecureResolver.CreateEvidenceForUrl(sourceURI)
    Dim myResolver As New XmlSecureResolver(New XmlUrlResolver(), myEvidence)
    
  • Se você estiver trabalhando em um ambiente semiconfiável e tiver código ou dados provenientes de uma fonte externa, mas não souber a origem da origem externa, seja:If you are working in a semi-trusted environment and you have code or data coming from an outside source, but you don't know the origin of the outside source, either:

    Defina o parâmetro de evidence a null.Set the evidence parameter to null. Isso não permite sem acesso a recursos.This allows no access to resources.

    - ou --or-

    Se seu aplicativo requer algum acesso aos recursos, solicite a evidência do chamador.If your application requires some access to resources, request evidence from the caller.

Aplica-se a

XmlSecureResolver(XmlResolver, String)

Inicializa uma nova instância da classe XmlSecureResolver com o XmlResolver e a URL fornecida.Initializes a new instance of the XmlSecureResolver class with the XmlResolver and URL provided.

public:
 XmlSecureResolver(System::Xml::XmlResolver ^ resolver, System::String ^ securityUrl);
public XmlSecureResolver (System.Xml.XmlResolver resolver, string? securityUrl);
public XmlSecureResolver (System.Xml.XmlResolver resolver, string securityUrl);
new System.Xml.XmlSecureResolver : System.Xml.XmlResolver * string -> System.Xml.XmlSecureResolver
Public Sub New (resolver As XmlResolver, securityUrl As String)

Parâmetros

resolver
XmlResolver

O resolvedor XML que é encapsulado pelo XmlSecureResolver.The XML resolver that is wrapped by the XmlSecureResolver.

securityUrl
String

A URL usada para criar o PermissionSet que será aplicado ao XmlResolver subjacente.The URL used to create the PermissionSet that will be applied to the underlying XmlResolver. O XmlSecureResolver chama PermitOnly() no PermissionSet criado antes de chamar GetEntity(Uri, String, Type) no XmlResolver subjacente.The XmlSecureResolver calls PermitOnly() on the created PermissionSet before calling GetEntity(Uri, String, Type) on the underlying XmlResolver.

Exemplos

Este exemplo usa o XmlSecureResolver(XmlResolver, String) construtor para criar um XmlSecureResolver objeto que tem permissão para acessar apenas seu site de intranet local.This example uses the XmlSecureResolver(XmlResolver, String) constructor to create an XmlSecureResolver object that is allowed to access your local intranet site only.

XmlSecureResolver myResolver = new XmlSecureResolver(new XmlUrlResolver(), "http://myLocalSite/");
Dim myResolver As New XmlSecureResolver(New XmlUrlResolver(), "http://myLocalSite/") 

Comentários

Importante

Há diferenças na infraestrutura de segurança para código em execução no .NET Framework Common Language Runtime (CLR) e no código em execução no CLR integrado no Microsoft SQL Server 2005.There are differences in the security infrastructure for code running on the .NET Framework common language runtime (CLR) and for code running on the CLR that is integrated within Microsoft SQL Server 2005. Isso pode levar a casos em que o código desenvolvido para o .NET Framework CLR funciona de forma diferente quando usado no SQL Server CLR integrado.This can lead to cases where code developed for the .NET Framework CLR operates differently when used on the SQL Server integrated CLR. Uma dessas diferenças afeta a XmlSecureResolver classe quando você tem evidências com base em uma URL (ou seja, quando você usa o CreateEvidenceForUrl método ou o XmlSecureResolver(XmlResolver, String) Construtor).One of these differences affects the XmlSecureResolver class when you have evidence that is based on a URL (that is, when you use the CreateEvidenceForUrl method or the XmlSecureResolver(XmlResolver, String) constructor). O mecanismo de resolução de política do CLR integrado SQL Server não usa as Url Zone informações ou.The policy resolution mechanism of the SQL Server integrated CLR does not use the Url or Zone information. Em vez disso, ele concede permissões com base no GUID que o servidor adiciona quando os assemblies são carregados.Instead, it grants permissions based on the GUID that the server adds when assemblies are loaded. Ao usar o XmlSecureResolver no SQL Server CLR integrado, forneça qualquer evidência necessária diretamente usando um especificado PermissionSet .When you use the XmlSecureResolver in the SQL Server integrated CLR, provide any required evidence directly by using a specified PermissionSet.

Aplica-se a