C# – Request for the permission of type ‘System.Web.AspNetHostingPermission”

asp.netclocalhost

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.

Best Answer

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