Sarah Weinberger
Sarah Weinberger

Reputation: 15561

ASP.Net: MySQL Error SecurityException: System.Security.Permissions.SecurityPermission

I am receiving the following error message:

Server Error in '/' Application.

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: System.Security.Permissions.SecurityPermission

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: 
[SecurityException: System.Security.Permissions.SecurityPermission]
   MySql.Data.MySqlClient.MySqlClientFactory..cctor() +23

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272

MySQL: mysql-connector-net-6.7.4

The problem only occurs if run from the shared web hosting environment. The site works great locally. I know the version of the .Net connector that my shared hosting environment uses, as that was another issue that I resolved and I was in communication with the hosting provider.

The error is interesting. I can go to the default page, no issues, the very first time. I then go to bring up a popup dialog, which throws another error message box.

Exception has been thrown by the target of an invocation.

The above is everything, except for the okay button.

I can bring up the first popup, a sign in dialog, which comes up. That dialog does not invoke MySQL. I bring up the second dialog, a registration dialog, which then throws the "Exception has been thrown..." message box. After that, I cannot go back into the sign-in dialog, as I get the "Exception has..." message box. If I press F5 to refresh the browser (IE or Chrome), I get the error from above. The above error indicates MySQL and some permissions.

I am suspecting that the "Exception has been thrown..." error is the result of the same MySQL, just the page has memory. Closing the browser window and launching the browser window again does not help, although on Chrome that works, just the browser window there really has to close down all the way.

I am in a shared hosting environment, so I have access to basically nothing, so I do not have access to any logs, at least that I can think of.

One final thought that may or may not be relevant. Yesterday and previous days my development work was done on a system with Windows 7 Professional and Visual Studio 2012 Professional (all latest service packs and updates), whereas today I am working at a different computer of mine, which is a system with Windows 8 Professional and Visual Studio 2012 Ultimate (all latest service packs and updates on the OS and VS). I was reading some other posts on unrelated issues that people with VS2012 Ultimate had issues, so I am not sure that has anything to do with it, but that is something that changed from yesterday to today.

Yes, I deleted everything off of the server and uploaded everything anew. I did a clean solution first, built the release, and then published. I still received the same error.

Any thoughts?

Upvotes: 1

Views: 2241

Answers (1)

Dikla Yakovski
Dikla Yakovski

Reputation: 41

By default most hosts use "Medium" trust level. You can change your web.config as below to get full trust:

<configuration> 
  <system.web> 
    <trust level="Full" /> 
  </system.web> 
</configuration>

Upvotes: 4

Related Questions