I think, this is quite common situation nowadays, so its surprising, that I have troubles finding nice and clean solution for it (even here at SO).
I have my ASP.NET MVC3 web application using Entity Framework 4.1 with code-first approach (using DatabaseInitializer to seed default data). I also tried two database options: SQL Express 2008 R2 and SQL Compact 4. Everything is working fine on local.
Now I want to host my app so I found hosting (middle one called 'optimal') and finally (after some issues) got into state, where I am getting medium-trust error (I believe).
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.
Let's take as fact that I can't configure that hosting any way and I do not think, that they are going to switch me to full-trust.
What do I have to do, to make my application work on medium-trust hosting?
Edit: I have found some answers that are usually propagating setting medium trust at local dev and just do it like that, so my question could now be something like:
What are "top 5 reasons" why your ASP.NET MVC3 EF 4.1 app won't work at medium-trust?
Edit: I have added bounty to this becuase I would like开发者_如何转开发 to see some discussion.. or at least more oppinions/experiences, containing more than just "set medium trust at local dev". Maybe there is nothing to discuss here, but I am just curious because I already spent more time on this than I would like.
I've seen other people complain of the same error when the server did not have .NET 3.5 Service Pack 1 and were able to work around it by putting the DLLs in their bin folder.
There's also a little more info here about a few things to check: log4net throwing Security Exception in ASP.Net MVC web application
Do you have the latest EF Code First library? Everything before the RC was not medium trust compatible.
If you are going to use SQL CE 4, it is medium trust compatible but did you deploy the SQL CE database engine files?
Are you sure your problem is EF Code First? AKA - Have you tried just deploying a simple MVC site first and getting it running? Here's an article on setting up MVC in medium trust and another on bin deploying MVC3 for hosts who aren't running/supporting MVC3 yet.
精彩评论