I'm developing an ASP.NET Core application that will be hosted behind IIS using IISIntegration. In the past, I've already developed a few ASP.NET Core apps, but all of them have been hosted in a Windows service, with IIS acting as a reverse proxy through URL rewriting. Now instead I have to use AspNetCoreModule.
I'm wondering what happens to Program.Main()
. Specifically, I call EntityFrameworkCore's EnsureCreated()
there, before building the web host. However, even though my application launches correctly and even responds to requests, the database was not populated with the necessary tables.
How can I solve this problem?
since there is a bit more to it i decided to add the rest of the code i used for it
var scopeFactory = app.ApplicationServices.GetRequiredService<IServiceScopeFactory>();
using (var scope = scopeFactory.CreateScope())
{
var db = scope.ServiceProvider.GetRequiredService<DbContext>();
db.Database.Migrate();
}