Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get current ASP.NET Trust Level programmatically

Tags:

asp.net

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

like image 926
Luca Martinetti Avatar asked Jun 30 '09 15:06

Luca Martinetti


1 Answers

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;
}
like image 126
Esteban Araya Avatar answered Nov 04 '22 18:11

Esteban Araya