2012-03-20 69 views
2

如何從.NET測試應用程序是否以完全信任的方式運行?測試.NET應用程序是否以完全信任運行

我的應用程序運行在.NET 2.0中,需要使用該框架。

+2

http://msdn.microsoft.com/en-us/library/0d005ted.aspx – 2012-03-20 02:23:46

+0

你只是想測試應用程序是否在完全信任運行,或者你想阻止其運行畢竟,如果它有限制的許可授予? – 2012-03-20 12:13:44

回答

3

看起來像是有一個博客Finding out the current trust level in asp.net看起來很有前途。我在這裏粘貼代碼以防博客死亡。

// 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. 
相關問題