AspNetHostingPermission exception got you down? Unblock Your Assemblies.
We ran into trouble with a web applications deployment of our only .Net product without a windows installer. Little did we know when you zip up a web application, have your on-site expert consultant download said zip file and extract it with Windows Explorer (Note: it does not happen with WinRar or 7zip) You will run into this exception trying spin up that web application.
Description: The application attempted to perform an operation not allowed by the security policy. To grant this application the required permission please contact your system administrator or change the application’s trust level in the configuration file.
Exception Details: System.Security.SecurityException: Request for the permission of type ‘System.Web.AspNetHostingPermission, System, Version=220.127.116.11, Culture=neutral, PublicKeyToken=b77a5c561934e089′ failed.
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
You have happened into another in my series of blog posts where I relay some wisdom that has already been well covered with the subversive desire to never forget the answer in hopes to not waste the time of myself and others here at Dovetail and you my friend. Sadly I failed to use the Google well and this took way too long to fix. Hence this cathartic post. Enjoy.
We’re From Redmond and We’re Here To Help
Windows is trying to protect you from running untrusted code you’ve found on the InterWebs. I only wish that the exception above would give you some small clue as to its cause. Instead it is as if the ASP.Net team is blaming the exception on a your web server administrator and by proxy your ASP.Net Trust Level which it is not. This might lead you, my friend, down the wrong wrong path into the weeds. Don’t go there.
Right click on the zip file, the individual executable or assembly which you downloaded from that nasty untrusted zone of the InterWebs (a.k.a Internet.)
There you go. You’ll notice I use WinRar I like it. One of the reasons I like it is when I extract files with it it treats me like an Adult. WinRar does not block my files.
Windows Explorer treats you different. It puts on the kid gloves and coddles you and tells you everything is going to be OK and no scary scary naughty code from the InterWebs is going to hurt you one bit. Windows Explorer will block those nasty assemblies, executables and documentation so they are completely useless and will cause your web application to throw nonsensical errors wasting everyone’s time when they could be at home with loved ones or out at the pub laughing gleefully.
Unblock That Code
If you know where the code came from. Go ahead click that Unblock button. Unblock it that code. Go ahead and hook that code up to your web server and have it tell the world how awesome you are.