How to determine if the current application is Medium Trust

萝らか妹 提交于 2019-12-03 16:32:54

This article here describes a mechanism to determine the trust level:

Finding out the current trust level in ASP.NET

Here is the code just in case the link dies:

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

I just tested it in an ASP.NET MVC3 application running at Medium and then Full trust and it does what it says on the tin.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!