Export (0) Print
Expand All

HostSecurityManager.DetermineApplicationTrust Method

Note: This method is new in the .NET Framework version 2.0.

Determines whether an application should be executed.

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

public virtual ApplicationTrust DetermineApplicationTrust (
	Evidence applicationEvidence,
	Evidence activatorEvidence,
	TrustManagerContext context
)
public ApplicationTrust DetermineApplicationTrust (
	Evidence applicationEvidence, 
	Evidence activatorEvidence, 
	TrustManagerContext context
)
public function DetermineApplicationTrust (
	applicationEvidence : Evidence, 
	activatorEvidence : Evidence, 
	context : TrustManagerContext
) : ApplicationTrust

Parameters

applicationEvidence

The Evidence for the application to be activated.

activatorEvidence

Optionally, the Evidence for the activating application domain.

context

A TrustManagerContext that specifies the trust context.

Return Value

An ApplicationTrust object that contains trust information about the application.

Exception typeCondition

ArgumentNullException

applicationEvidence is a null reference (Nothing in Visual Basic).

ArgumentException

An ActivationArguments object could not be found in the application evidence.

-or-

The ActivationContext property in the activation arguments is a null reference (Nothing in Visual Basic).

This method can be overridden by a derived class. The base implementation calls the application security manager to determine if the application should be executed.

The base implementation does not use the activator evidence. However, an overridden implementation could use the activator evidence to determine the security evidence for the application domain attempting to activate the application.

The following code example shows an override of the DetermineApplicationTrust method for a custom host security manager. This example is part of a larger example provided for the HostSecurityManager class.

[SecurityPermissionAttribute(SecurityAction.Demand, Execution = true)]
[SecurityPermissionAttribute(SecurityAction.Assert, Unrestricted = true)]
public override ApplicationTrust DetermineApplicationTrust(Evidence applicationEvidence, Evidence activatorEvidence, TrustManagerContext context)
{
    if (applicationEvidence == null)
        throw new ArgumentNullException("applicationEvidence");

    // Get the activation context from the application evidence.
    // This HostSecurityManager does not examine the activator evidence
    // nor is it concerned with the TrustManagerContext;
    // it simply grants the requested grant in the application manifest.

    IEnumerator enumerator = applicationEvidence.GetHostEnumerator();
    ActivationArguments activationArgs = null;
    while (enumerator.MoveNext())
    {
        activationArgs = enumerator.Current as ActivationArguments;
        if (activationArgs != null)
            break;
    }

    if (activationArgs == null)
        return null;

    ActivationContext activationContext = activationArgs.ActivationContext;
    if (activationContext == null)
        return null;

    ApplicationTrust trust = new ApplicationTrust(activationContext.Identity);
    ApplicationSecurityInfo asi = new ApplicationSecurityInfo(activationContext);
    trust.DefaultGrantSet = new PolicyStatement(asi.DefaultRequestSet, PolicyStatementAttribute.Nothing);
    trust.IsApplicationTrustedToRun = true;
    return trust;
}

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2014 Microsoft