2009-06-30 112 views

回答

22

dmitryr's blog

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

下面的代碼獲取當前ASP.NET信任級別編程方式使用官方配置API:

using System.Web; 
using System.Web.Configuration; 

... 

var trust = WebConfigurationManager.GetSection("system.web/trust") as TrustSection; 
return trust.Level; 
+0

它是如此明顯,對不起。 – 2015-09-16 18:46:12

相關問題