以编程方式获取当前的ASP.NET信任级别

前端之家收集整理的这篇文章主要介绍了以编程方式获取当前的ASP.NET信任级别前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
有没有API来获取当前的ASP.NET信任级别?

解决方法

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

猜你在找的asp.Net相关文章