Cedric Arnould
Cedric Arnould

Reputation: 2383

Asp.Net Core 2.0.5 deployment on IIS

I try to deploy my asp.net Core 2.0.5 project to IIS. I created a default Asp.Net Core MVC application and I deployed it. Every thing worked correctly. But when I added in program.cs:

using (var scope = host.Services.CreateScope())
{
    var initializer = scope.ServiceProvider.GetService<MasterDbInitializer>();
    initializer.Seed();
}

and in startup.cs:

        services.AddScoped<MasterDbInitializer>();

and MasterDbInitializer.cs:

public class MasterDbInitializer
{
    private readonly MasterDbContext _ctx;

    public MasterDbInitializer(MasterDbContext ctx)
    {
        _ctx = ctx;
    }

    public void Seed()
    {
        // Run Migrations
        _ctx.Database.Migrate();

    }
}

I have : HTTP Error 502.5 - Process Failure and the Database is not generated.

So to have more information, in web.config I updated stdoutLogEnabled to true and I added in startup.cs loggerFactory.AddFile("Logs/myapp-{Date}.txt"); (Serilog) to have more log.

This is what I have in the log:

info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[0] User profile not available. Using > 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ASP.NET\4.0.30319.0\AutoGenKeys\XXXX\DataProtection' as key repository and Windows DPAPI to encrypt keys at rest. warn: Microsoft.EntityFrameworkCore.Model.Validation[20601] The 'bool' property 'HasBeenReroutedToCustomer' on entity type > 'ActivationRequest' is configured with a database-generated default. This > > default will always be used when the property has the value 'false', since this is the CLR default for the 'bool' type. Consider using the nullable 'bool?' type instead so that the default will only be used when the property value is 'null'. warn: Microsoft.EntityFrameworkCore.Model.Validation[20601] The 'bool' property 'HasBeenViewed' on entity type 'ActivationRequest' is configured with a database-generated default. This default will always be used when the property has the value 'false', since this is the CLR default for the 'bool' type. Consider using the nullable 'bool?' type instead so that the > default will only be used when the property value is 'null'. warn: Microsoft.EntityFrameworkCore.Model.Validation[20601] The 'bool' property 'Deleted' on entity type 'MasterDeviceIdentifier' is configured with a database-generated default. This default will always be used when the property has the value 'false', since this is the CLR default for the 'bool' type. Consider using the nullable 'bool?' type instead so that the default will only be used when the property value is 'null'. info: Microsoft.EntityFrameworkCore.Infrastructure[10403] Entity Framework Core 2.0.1-rtm-125 initialized 'MasterDbContext' using provider 'Microsoft.EntityFrameworkCore.SqlServer' with options: None

Upvotes: 2

Views: 4211

Answers (1)

Martin Ullrich
Martin Ullrich

Reputation: 100543

As mentioned in the Host ASP.NET Core on Windows with IIS document, configure the App Pool to allow for user profiles if no other data protection store is used:

Configure the IIS Application Pool to load the user profile

This setting is in the Process Model section under the Advanced Settings for the app pool. Set Load User Profile to True. This stores keys under the user profile directory and protects them using DPAPI with a key specific to the user account used for the app pool.

Upvotes: 3

Related Questions