我正在尝试将我的 MVC3(我也尝试过 MVC4)发布到我的共享主机(安装了 MVC3),但是我收到了这个安全异常:
安全异常
说明:应用程序试图执行安全策略不允许的操作。要授予此应用程序所需的权限,请联系您的系统管理员或在配置文件中更改应用程序的信任级别。
Exception Details: System.Security.SecurityException: Request failed.
源错误:
Line 20: @foreach (var item in Model) {
以下是错误的前几行:
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
我的共享主机运行信任级别 = 中。所以在我本地机器上的项目中,我还在网络配置中将信任设置为中等,它运行得很好:
<trust level="Medium" originUrl="" />
我将我的数据库上传到服务器,所以我没有重新使用 EF 在服务器上重建我的数据库。
但看看错误,我认为LocalDbConnectionFactory可能是罪魁祸首?还是应该在部署后留在那里?我的 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>
这是我的上下文类:
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; }
}
我错过了什么吗?共享主机是否应该安装一些东西来使 LocalDB 工作?或者有没有办法绕过这个并使我的 LINQ 查询工作?
请帮忙
问候大卫