是否有API来获取当前的ASP.NET信任级别?
答案 0 :(得分:22)
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;
}
答案 1 :(得分:0)
The following code get current ASP.NET Trust Level programmatically using the official configuration API:
using System.Web;
using System.Web.Configuration;
...
var trust = WebConfigurationManager.GetSection("system.web/trust") as TrustSection;
return trust.Level;