2012-03-20 5 views
2

Comment tester à partir de .NET si une application est en cours d'exécution avec une confiance totale?Tester si une application .NET s'exécute en toute confiance

Mon application fonctionne sous .NET 2.0 et doit fonctionner avec ce framework.

+2

http://msdn.microsoft.com/en-us/library/0d005ted.aspx –

+0

Est-ce que vous voulez simplement vérifier si l'application est en cours d'exécution en pleine confiance, ou voulez-vous empêcher de courir du tout s'il a une autorisation d'autorisation restreinte? –

Répondre

3

On dirait qu'il existe un blog Finding out the current trust level in asp.net qui semble prometteur. J'ai collé le code ici au cas où le blog meurt.

// Here is a sample code that returns the current trust level, assuming this 
// code (or the calling code up the stack), is not loaded from GAC: 

AspNetHostingPermissionLevel GetCurrentTrustLevel() { 
    foreach (AspNetHostingPermissionLevel trustLevel in 
    new AspNetHostingPermissionLevel [] { 
     AspNetHostingPermissionLevel.Unrestricted, 
     AspNetHostingPermissionLevel.High, 
     AspNetHostingPermissionLevel.Medium, 
     AspNetHostingPermissionLevel.Low, 
     AspNetHostingPermissionLevel.Minimal 
     }) { 
    try { 
     new AspNetHostingPermission(trustLevel).Demand(); 
    } 
    catch (System.Security.SecurityException) { 
     continue; 
    } 

    return trustLevel; 
    } 
    return AspNetHostingPermissionLevel.None; 
} 

// The result can be cached in a static field 
// for the duration of the app domain lifetime. 
Questions connexes