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 :
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 failed.
Source Error:
Line 20: @foreach (var item in Model) {
Here are the first few lines of the error :
System.Security.CodeAccessSecurityEngine.Check(Object demand, StackCrawlMark& stackMark, Boolean isPermSet) +0
System.Security.CodeAccessSecurityEngine.Check(PermissionSet permSet, StackCrawlMark& 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
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 :
<trust level="Medium" originUrl="" />
I uploaded my database to the server, so I am not re-using EF to rebuild my database on the server.
But looking at the errors, I think the LocalDbConnectionFactory might be the culprit? Or should this stay there after deploying? part of my web.config :
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=liveServer,com;Initial Catalog=sarmie;Persist Security Info=True;User ID=liveServer;Password=liveServer;" providerName="System.Data.SqlClient" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
</entityFramework>
Here is my Context class :
public class MvcApplication4Context : DbContext
{
//public MvcApplication4Context()
//{
// System.Data.Entity.Database.SetInitializer(new System.Data.Entity.DropCreateDatabaseIfModelChanges<MvcApplication4.Models.MvcApplication4Context>());
//}
public DbSet<MvcApplication2.Models.Ad> Ads { get; set; }
}
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?
Please help
Regards David