title: Deploy MVC to shared host causing Security Exception
body: <p>I am trying to publish my MVC3 (I tried MVC4 as well) to my shared host (which has MVC3 installed), but I am getting this  security exception :</p>
  <blockquote>
  <p>Security Exception</p>
  <p>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.</p>
  </blockquote>
  <pre><code>Exception Details: System.Security.SecurityException: Request failed.
  </code></pre>
  <blockquote>
  <p>Source Error:</p>
  </blockquote>
  <pre><code>Line 20: @foreach (var item in Model) {
  </code></pre>
  <p>Here are the first few lines of the error :</p>
  <pre><code>System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark&amp; stackMark, Boolean isPermSet) +0
     System.Security.CodeAccessSecurityEngine.Check(PermissionSet permSet, StackCrawlMark&amp; stackMark) +31
     System.Security.PermissionSet.Demand() +68
     System.Data.LocalDBAPI.**DemandLocalDBPermissions**() +241
     System.Data.LocalDBAPI.CreateLocalDBInstance(String instance) +32
     System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, Boolean withFailover) +5306971
     System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover) +145
     System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout) +262
     System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance) +307
     System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions) +434
     System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions) +225
  </code></pre>
  <p>My shared host is running the trust level = medium. So in my project on my localmachine, I also set the trust to medium in the web config, and it runs just fine :</p>
  <pre><code>&lt;trust level=&quot;Medium&quot; originUrl=&quot;&quot; /&gt;
  </code></pre>
  <p>I uploaded my database to the server, so I am not re-using EF to rebuild my database on the server.</p>
  <p>But looking at the errors, I think the <strong>LocalDbConnectionFactory</strong> might be the culprit? Or should this stay there after deploying?
  part of my web.config :</p>
  <pre><code>&lt;connectionStrings&gt;
  &lt;add name=&quot;DefaultConnection&quot; connectionString=&quot;Data Source=liveServer,com;Initial Catalog=sarmie;Persist Security Info=True;User ID=liveServer;Password=liveServer;&quot; providerName=&quot;System.Data.SqlClient&quot; /&gt;
  &lt;/connectionStrings&gt;
  &lt;entityFramework&gt;
  &lt;defaultConnectionFactory type=&quot;System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework&quot;&gt;
  &lt;parameters&gt;
      &lt;parameter value=&quot;v11.0&quot; /&gt;
  &lt;/parameters&gt;
  &lt;/defaultConnectionFactory&gt;
  &lt;/entityFramework&gt;
  </code></pre>
  <p>Here is my Context class :</p>
  <pre><code>public class MvcApplication4Context : DbContext
      {
          //public MvcApplication4Context()
          //{
          //    System.Data.Entity.Database.SetInitializer(new System.Data.Entity.DropCreateDatabaseIfModelChanges&lt;MvcApplication4.Models.MvcApplication4Context&gt;());
          //}
  
          public DbSet&lt;MvcApplication2.Models.Ad&gt; Ads { get; set; }
      }
  </code></pre>
  <p>Am I missing something? Should the Shared host install something to make LocalDB work? Or is there a way to bypass this and make my LINQ queries work?</p>
  <p>Please help</p>
  <p>Regards
  David</p>