How to determine if the current application is medium trust

I am trying to make sure my ASP.Net library will work under Medium Trust. I'm having problems, but that I need to disable the bit of code if it runs under medium trust.

How to determine from C # if the current application is average?

In particular, I am trying to read the customErrors section from web.config and I am getting security errors

+5
source share
1 answer

This article describes the mechanism for determining the level of trust:

Finding the current level of trust in ASP.NET

Here is the code just in case the link freezes:

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 MVC3, Medium, Full trust, , .

+3

All Articles