Request for the permission of type 'System.Web.AspNetHostingPermission"

37,701

Solution 1

This error usually happens if you Map your application folder on Network Drive or open Solution file from UNC Path. somthing like this:

Invalid Example: \\my-server\my-project

Try to open your solution from direct path

Valid Example: C:\Project\MyProject

You can also make change to your privilege of App Pool Identity but it's not recommanded:

Web Server (IIS) > App Pool Identity > Advance Settings > Set Identity as Network Service

Solution 2

the one shot solution worked for me was to set the App Pool Identity(Advance Settings) to Network Service

Solution 3

Try to set "Load User Profile" value of your application pool to "True". It worked for me.

Solution 4

For what its worth, I found that the AjaxControlKit.dll on the deployed server was blocked. To resolve this, I copied over the dll to a new folder then copied and pasted in the bin folder. I guess .net doesn't like a dll being copied over directly to the web folder

Solution 5

you can run the following command to Grant FullTrust to remote share:

C:\Windows\Microsoft.NET\Framework\v2.0.50727>caspol.exe -m -ag 1 -url "file:////\yourcomputername\yoursharename*" FullTrust -exclusive on

Hope this helps.

Share:
37,701
MARKAND Bhatt
Author by

MARKAND Bhatt

Updated on June 23, 2021

Comments

  • MARKAND Bhatt
    MARKAND Bhatt almost 3 years

    I am facing a problem for running my website.

    I have developed the website and when i hit F5 to view the results i am presented with this error

    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=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

    Error Page

    How can i solve this problem.

  • RyanfaeScotland
    RyanfaeScotland over 9 years
    +1 From what I've found this is fairly undocumented around the web but has caught me out twice now. Thanks for sharing.
  • htxryan
    htxryan over 8 years
    Here is an official Microsoft support article confirming this issue, along with suggested fixes: support.microsoft.com/en-us/kb/320268
  • Gabriel
    Gabriel over 8 years
    Thanks, this did the trick, must be marked as the answer. In my environment admin rights are not permited.
  • Shaiju T
    Shaiju T almost 8 years
    for Go daddy i just made make change in web.config , check this
  • Levimatt
    Levimatt about 7 years
    But, what happen if I have all solution files in a network drive pointing to a TFS?
  • Shrink
    Shrink over 6 years
    Glad it helped!
  • N1njaB0b
    N1njaB0b over 6 years
    FYI, I had this problem twice. The first time, the 32-bit solution from @Shrink was the answer. This time, it was AjaxControlToolkit.dll needed to be unblocked. Just goes to show any one of these answers could be valid.
  • Piotr Korlaga
    Piotr Korlaga over 2 years
    Works like a charm! Thanks a lot. btw. don't forget to restart your application pool after running this command