![](/img/trans.png)
[英]Server Error Resource cannot be found 404 when trying to access directory using HTTPS on IIS 8.5 but works using HTTP
[英]Cannot create DB using EntityFramework 6 when the project is deployed on an IIS 8.5
我有一个 Visual Studio 2019 项目,该项目使用 ASP.NET 和 C# 发布了 web 应用程序(web api)。
我们使用 EntityFramework 6 Code-First 策略来访问 SQL 服务器数据库。
When I run it locally or on an Azure Service, everything is great, but when I deploy this web app onto an IIS 8.5 in a server running Windows Server 2012 R2, for some reason EntityFramework 6 is not able to create the database.
我们使用以下内容创建数据库:
Database.SetInitializer(new MigrateDatabaseToLatestVersion<MobileServiceContext, Migrations.Configuration>("MS_TableConnectionString"));
我们指向的是本地 SQL Server 2014。
我们创建一个 DbContext 的子级来处理 EntityFramework 上下文,如下所示:
public class MobileServiceContext : DbContext
{
public const string CONNECTION_STRING_KEY = "MS_TableConnectionString"; // "MS_TableConnectionString";
public const string CONNECTION_STRING_NAME = "Name=" + CONNECTION_STRING_KEY; // "MS_TableConnectionString";
public MobileServiceContext() : base(CONNECTION_STRING_NAME)
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
... we add some logic here to create indexes etc.
}
}
当我尝试在服务器上远程调试应用程序时,在第一次创建 MobileServiceContext 类型的 object 时,执行只是没有提前 go (我什至尝试在创建时添加 ZA75131CB1C90CDAFC1C0A52AE24Z,但它没有'不要进入异常捕获...)。
显然我们从来没有进入 OnModelCreating 方法......
同样,相同的代码在本地和 Azure 上都能完美运行。
我应该在我的服务器中配置任何东西吗?
只是为了记录,事实证明我必须在 web.config 中添加以下重定向:
<dependentAssembly>
<!-- Don't change this redirect!! It is part of a problem with a MS bug, see here https://github.com/dotnet/corefx/issues/25773 -->
<assemblyIdentity name="System.Net.Http" publicKeyToken="B03F5F7F11D50A3A" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.0.0.0" />
</dependentAssembly>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.