Page 1 of 1

Security Exception ( System.Security.SecurityException: Request for the permission of type 'System.Security.Permissions)

Posted: Fri 09 Mar 2007 01:42
by cesarvegamx
So, I'm getting this 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.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
The error happen just when deploying the application to a shared host with medium trust level. It does not happen when there's full trust.

You can see the error here:
http://desktopdatabases.com/default2.aspx

Workaround

Posted: Fri 09 Mar 2007 16:26
by aukinfo
Hi, I have had the very same problem.

I am also in a medium trust env, running Version=3.55.20.0.

My login page was giving me the security error. But then I found that after I accessed a different page which permed a db connection, I was able to log on.
So I have put the following in the global.asax file application_start event and now all is fine again...apart from my other bugs

/* For some reason, this stops the security error seen in Medium Trust Environment */
CoreLab.MySql.MySqlConnection connection =
new CoreLab.MySql.MySqlConnection(ConfigurationManager.ConnectionStrings["cocConnectionString"].ConnectionString);
connection.Open();

CoreLab.MySql.MySqlCommand command = new CoreLab.MySql.MySqlCommand("Select '' from aspnet_profiles;", connection);
command.ExecuteNonQuery();

Posted: Sat 10 Mar 2007 03:38
by cesarvegamx
Well, in my case, I'm not even using asp.net membership!.

It is a simple query to a test table.

Posted: Mon 12 Mar 2007 08:21
by Alexey
cesarvegamx, are you granted SocketPermissions by your hosting parties?

Posted: Mon 12 Mar 2007 15:52
by cesarvegamx
Yes, see the web_mediumtrust.config on my provider:

Code: Select all


    
        
            
                
                    
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
                        
			
			
			
                    
                    
                        
                        
                        
                            
                            
                            
                            
                            
                            
                            
                            
                            
                            
                            
                            
                            
                            
			    

			    

			    
                        
                    
                    
                        
                        
                            
                        
                        
                            
                        
                        
                        	
                            
                                
                            
                            
                                
                            
                        
                    
                
            
        
    

Posted: Mon 12 Mar 2007 15:57
by cesarvegamx

Code: Select all

Is MySQLDirect .NET installed on the target machine (or at least CoreLab.*.dll assemblies are registered in the GAC)?
No, it is a shared hosting.

Code: Select all

Do you use direct mode?
Yes.
When exactly that error occurs? On Connection.Open() call?
It seems it is originated here: CoreLab.MySql.MySqlDirectFactory.CreateConnection()
You can see the stack trace in this sample site:
http://desktopdatabases.com/default2.aspx
Could you provide me with your web.config file and medium trust config file on the shared host?
The medium trust config file is in the post above.
The web.config was already sent by email on friday, together with the whole repro application.

Posted: Tue 13 Mar 2007 13:10
by Alexey
Your project is received and is being investigated.

Posted: Wed 14 Mar 2007 09:37
by Alexey
We have fixed the problem in MySQLDirect .NET beta. Look forward to the release, which is gonna be available this month.