14

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.

Damb
  • 14,410
  • 6
  • 47
  • 49
  • @Haacked: I made error report available [here](http://pastebin.com/ZxLu4jih) – Damb May 13 '11 at 02:21
  • looks like EF Code First can't create the database files on the server, have you tried creating the database files locally and copying them to the server. – Wim May 13 '11 at 07:03
  • @Wim: Yes I tried to use sql ce 4, generated db into app_data and deployed. Didn't work... (don't exactly remember why... was kinda busy latelty so I weren't able to digg into it too much). – Damb May 13 '11 at 13:46

2 Answers2

5

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

Community
  • 1
  • 1
Danny Tuppeny
  • 40,147
  • 24
  • 151
  • 275
1

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.

Kevin LaBranche
  • 20,908
  • 5
  • 52
  • 76
  • Thanks for reply. I have latest EF I believe (4.1). I didn't try deploying bin files of sqlce because a.) my provider says, they already support it; b.) I was using web deploy (from visual studio and also from web matrix) and I think some .dlls were automatically deployed there, when I used SQLCE4 provider. So this shouldn't need any manual work imo. And to answer your third question: I tried web deploying default 'bakery' site from web matrix and also an empty mvc app, both worked afaik (but I haven't debuggede them any deeply, I just saw they are running). – Damb May 18 '11 at 10:53