2009-06-30 20 views

Respuesta

22

De 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

El siguiente código póngase al nivel de confianza ASP.NET mediante programación utilizando la API de configuración oficial:

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

... 

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

era tan obvio, lo siento. –

Cuestiones relacionadas