【发布时间】:2018-01-24 04:05:51
【问题描述】:
我尝试将我的 asp.net Core 2.0.5 项目部署到 IIS。 我创建了一个默认的 Asp.Net Core MVC 应用程序并进行了部署。每件事都正常工作。 但是当我在program.cs中添加时:
using (var scope = host.Services.CreateScope())
{
var initializer = scope.ServiceProvider.GetService<MasterDbInitializer>();
initializer.Seed();
}
在startup.cs中:
services.AddScoped<MasterDbInitializer>();
和 MasterDbInitializer.cs:
public class MasterDbInitializer
{
private readonly MasterDbContext _ctx;
public MasterDbInitializer(MasterDbContext ctx)
{
_ctx = ctx;
}
public void Seed()
{
// Run Migrations
_ctx.Database.Migrate();
}
}
我有:HTTP 错误 502.5 - 进程失败并且没有生成数据库。
为了获得更多信息,我在 web.config 中将 stdoutLogEnabled 更新为 true 并在 startup.cs loggerFactory.AddFile("Logs/myapp-{Date}.txt"); (Serilog) 以获得更多日志。
这是我在日志中的内容:
信息:Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[0] 用户配置文件不可用。使用 > 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ASP.NET\4.0.30319.0\AutoGenKeys\XXXX\DataProtection' 作为密钥存储库和 Windows DPAPI 来加密静态密钥。 警告:Microsoft.EntityFrameworkCore.Model.Validation[20601] 实体类型 > 'ActivationRequest' 上的 'bool' 属性 'HaBeenReroutedToCustomer' 配置有数据库生成的默认值。当属性值为“false”时,将始终使用此 > > 默认值,因为这是“bool”类型的 CLR 默认值。考虑使用可为空的“布尔?”而是键入,以便仅当属性值为“null”时才使用默认值。 警告:Microsoft.EntityFrameworkCore.Model.Validation[20601] 实体类型“ActivationRequest”上的“bool”属性“HasBeenViewed”配置为使用数据库生成的默认值。当属性的值为“false”时,将始终使用此默认值,因为这是“bool”类型的 CLR 默认值。考虑使用可为空的“布尔?”而是键入,以便仅当属性值为“null”时才使用 > 默认值。 警告:Microsoft.EntityFrameworkCore.Model.Validation[20601] 实体类型“MasterDeviceIdentifier”上的“布尔”属性“已删除”配置为使用数据库生成的默认值。当属性的值为“false”时,将始终使用此默认值,因为这是“bool”类型的 CLR 默认值。考虑使用可为空的“布尔?”而是键入,以便仅当属性值为“null”时才使用默认值。 信息:Microsoft.EntityFrameworkCore.Infrastructure[10403] Entity Framework Core 2.0.1-rtm-125 使用提供程序“Microsoft.EntityFrameworkCore.SqlServer”初始化“MasterDbContext”,选项:无
【问题讨论】: