Alex Rivera | Logout

Get current ASP.NET Trust Level programmatically

Asked 2009-06-30T15:18:44.183
16

Is there an API to get the current ASP.NET Trust Level?

Edit
Report

1 Answer

22

From 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;
}
answered 2009-06-30T15:22:26.627

Your Answer