HostSecurityManager.GenerateAppDomainEvidence Method (Type)

.NET Framework (current version)
 

Requests a specific evidence type for the application domain.

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

public virtual EvidenceBase GenerateAppDomainEvidence(
	Type evidenceType
)

Parameters

evidenceType
Type: System.Type

The evidence type.

Return Value

Type: System.Security.Policy.EvidenceBase

The requested application domain evidence.

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<T> 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.

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;
}

.NET Framework
Available since 4.0
Return to top
Show: