ערוך

שתף באמצעות


HostSecurityManager.GenerateAppDomainEvidence(Type) Method

Definition

Requests a specific evidence type for the application domain.

public:
 virtual System::Security::Policy::EvidenceBase ^ GenerateAppDomainEvidence(Type ^ evidenceType);
public virtual System.Security.Policy.EvidenceBase GenerateAppDomainEvidence (Type evidenceType);
abstract member GenerateAppDomainEvidence : Type -> System.Security.Policy.EvidenceBase
override this.GenerateAppDomainEvidence : Type -> System.Security.Policy.EvidenceBase
Public Overridable Function GenerateAppDomainEvidence (evidenceType As Type) As EvidenceBase

Parameters

evidenceType
Type

The evidence type.

Returns

The requested application domain evidence.

Examples

The following example shows how to override the ProvideAppDomainEvidence method for a custom host security manager. This example is part of a larger example provided for the HostSecurityManager class.

public override Evidence ProvideAppDomainEvidence(Evidence evidence)
{
    Console.WriteLine("Provide evidence for the " + AppDomain.CurrentDomain.FriendlyName + " AppDomain.");
    if (evidence == null)
        return null;

    evidence.AddHostEvidence(new CustomEvidenceType());
    return evidence;
}
Public Overrides Function ProvideAppDomainEvidence(ByVal evidence As Evidence) As Evidence
    Console.WriteLine("Provide evidence for the " + AppDomain.CurrentDomain.FriendlyName + " AppDomain.")
    If evidence Is Nothing Then
        Return Nothing
    End If
    evidence.AddHostEvidence(New CustomEvidenceType())
    Return evidence

End Function 'ProvideAppDomainEvidence

Remarks

This method can be overridden by a derived class. The base implementation returns null.

The common language runtime calls this method when evidence of the specified type is needed for the current AppDomain. The returned value is used as host-supplied evidence, and is stored in the Evidence collection of the CurrentDomain property. You can use the Evidence.GetAssemblyEvidence method to obtain the generated evidence from the collection.

To get a callback to this method, hosts must specify the HostAppDomainEvidence flag in the Flags property.

This method of generating evidence allows hosts to delay evidence generation for an AppDomain until the evidence is needed. In the .NET Framework version 3.5 and earlier versions, it was necessary to provide AppDomain evidence at load time by overriding the ProvideAppDomainEvidence method. We recommend that you use GenerateAppDomainEvidence to provide evidence instead of overriding ProvideAppDomainEvidence.

The GenerateAppDomainEvidence method is called back into only for types of evidence that the host has specified in the override of the GetHostSuppliedAppDomainEvidenceTypes method.

A return value of null indicates that the host cannot generate evidence of this specific type.

Applies to