Search code examples
asp.net

The application attempted to perform an operation not allowed by the security policy


I have developed an Asp.net website in Visual Studio 2008 and it worked fine while using Vista OS but my workstation got upgraded to Windows 7 and I now get following error:

Security Exception 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.

I get this error while running on my local machine from within Visual studio... I have already googled the error but nothing i found helps so far. I don't get the error when deployed on server, just on my local.

The website references .dll projects that I have created in the same solution. The error seems to occur when I try to instaniate an object contained within any one of these .dll projects.

This setting in Web.config did not help:

<trust level="Full" originUrl="" />

neither did this:

<securityPolicy>
    <trustLevel  name="Full" policyFile="internal" />
</securityPolicy>

Solution

  • This is an old question, but I experienced this exact issue recently and as the problem existed on the local machine and not on a remote one like most of the rest of the information pulled up with this particular error, none of those solutions helped so I'm going to put my solution here.

    My issue was that I was using a networked workstation and trying to run a solution that was stored on a network drive. For some reason, my local machine did not trust that particular drive and it would not accept any of the attempts to raise the trust level of the application.

    Once I realized the issue was the drive itself, I simply moved the entire solution over to another one and it solved the problem for me. I imagine that a talk with the Network Admin about their permissions could likely helped to correct the error also, but just switching the solution to a local drive fixed the issue that I was having and might work for others.