Sunday, August 5, 2012

“Request for the permission of type 'System.Web.AspNetHostingPermission’” fix

If you try to transfer an old DNN installation to a brand new Windows Server 2008 R2 you will probably run in the following run time error:
" System.Security.SecurityException: Request for the permission of type 'System.Web.AspNetHostingPermission, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed."

This is due to the restricted nature of  ApplicationPoolIdentity compared to the old Network Service account that used to run in previous versions of IIS.
There are three ways to go around this:
  1. Change the App pool identity to Network Service
  2. Enable “Load User Profile” in the App pool identity (never tested but found it somewhere in stack overflow)
  3. Use caspol to trust the dlls that are being blocked to help protect the computer
In order to use caspol you will have to open a command prompt in Administrator context and issue the following statement:

%windir%\Microsoft.NET\Framework\v2.0.50727\caspol.exe -m -ag 1 -url "file:////C:\WebApplicationFiles\*" FullTrust -exclusive on

assuming your application is in “C:\WebApplicationFiles”. This will prompt you that you are about to alter security policy and if you say “yes” all dlls will be unblocked. So make sure you trust them prior doing that.

Hope this helps.

No comments: