Security Exception, AspNetHostingPermission Error …

Problem

You get this error:

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.

When using Microsoft SharePoint

This error can occur when your server runs Microsoft SharePoint Services.  Try disabling the SharePoint service and make sure your server is running .NET Framework 1.1.

Please also review:

http://blogs.msdn.com/pandrew/archive/2004/05/09/128569.aspx

If you are not running SharePoint, then this issue reflects the security policy of your computer.

Virtual Directory on Microsoft IIS is not set to allow anonymous access

See Virtual Directory on Microsoft IIS Does Not Allow Anonymous Access for instructions on allowing anonymous access.

The ASPNET user is not configured properly

Check to make sure the ASPNET account has permissions to the folder containing your application.  Your ASPNET user needs full permissions in order for your application to run properly.

See ASP.NET User Does Not Have Permissions to Your Application Folder for instructions on granting access permissions.

Application properly deployed

Make sure that you have followed the instructions in Part VI:  Deploying Applications Into Production.

Check event viewer

Look in the Event Viewer on the machine, specifically at the Application section.  If you see multiple errors or warnings within a short period of time, look at the first one to see the root cause.  Sometimes errors have a cascading impact, so always looking at the first one will give you information about the root cause.

See Also

Part VII:  Troubleshooting Applications

Application Won’t Run

Application Runs But No Data is Displayed

Application Error Messages