1

I found the similar question on Msdn's forum but without answer (you can check it here) .Net 4.0 came with obsolete method

IsUnderHighTrust = SecurityManager.IsGranted( 
  new AspNetHostingPermission( AspNetHostingPermissionLevel.Unrestricted ) );

As a replacement it is suggested to use AppDomain.CurrentDomain.PermissionSet

var permission = new PermissionSet(PermissionState.None);
permission.AddPermission(
  new AspNetHostingPermission(AspNetHostingPermissionLevel.Unrestricted));

IsUnderHighTrust = permission.IsSubsetOf(AppDomain.CurrentDomain.PermissionSet); 

But PermissionSet is also requires Full trust mode.

So the obvious question - how to check under Asp .Net 4.0 if application is under Full or Medium Trust mode?

Cheburek
  • 2,103
  • 21
  • 32

1 Answers1

0

How about putting a try/catch around a block of code (like the PermissionSet check above) that requires full-trust and catch on a SecurityException? It's not as pretty because this isn't what a try/catch should normally be used for, but seems it would accomplish the goal none the less.

Michael Cox
  • 1,281
  • 13
  • 15
  • That looks like a rude hack. I'd better use obsolete method. I'm wondered about such MS solution... – Cheburek Feb 11 '12 at 14:31