16
是否有獲取當前ASP.NET信任級別的API?以編程方式獲取當前ASP.NET信任級別
是否有獲取當前ASP.NET信任級別的API?以編程方式獲取當前ASP.NET信任級別
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;
}
下面的代碼獲取當前ASP.NET信任級別編程方式使用官方配置API:
using System.Web;
using System.Web.Configuration;
...
var trust = WebConfigurationManager.GetSection("system.web/trust") as TrustSection;
return trust.Level;
它是如此明顯,對不起。 – 2015-09-16 18:46:12