IMPORTANT!
This forum is now archived. Click here for the New Support Forum
Installing IdentityServer4
Quote from filipedine on October 13, 2020, 8:33 pmHi All,
It is my first time installing IdentitySever on my QuickApp and I am using this link from Eben has a guide. However I am getting a error related with DbContext.
"InvalidOperationException: No database provider has been configured for this DbContext. A provider can be configured by overriding the DbContext.OnConfiguring method or by using AddDbContext on the application service provider. If AddDbContext is used, then also ensure that your DbContext type accepts a DbContextOptions<TContext> object in its constructor and passes it to the base constructor for DbContext."
This exception was generated at:
QuickApp.IdentityServerDbInitializer.SeedAsync() in IdentityServerDBInitializer.csI'm probably missing something from this part of the post:
"Note that we use the override keyword for our SeedAsync() method. That means we have to add the virtual keyword to our base implementation in the file DatabaseInitializer.cs ( i.e. virtual public async Task SeedAsync()).
Also we now have additional DbContexts in our solution (i.e. IdentityServer’s PersistedGrantDbContext and ConfigurationDbContext), so we need to modify the constructor of our own ApplicationDbContext class and restrict the parameter it can accept to the type DbContextOptions<ApplicationDbContext>, else dependency injection will pass in the wrong DbContextOptions that belongs to one of the other DbContext.
We do this by changing the line public ApplicationDbContext(DbContextOptions options) : base(options) to public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options)"What I did was:
In DatabaseInitializer.cs
Change: public async Task SeedAsync()
to: virtual public async Task SeedAsync()
In ApplicationDbContext.cs
Changed: public ApplicationDbContext(DbContextOptions options) : base(options)
To: public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options)
Finally and not shore if this has any impact:
- I've placed the file IdentityServerDBInitializer.cs under the QuickApp folder at the same level as the startup.cs file is. Is this correct or should this be under the DAL project at the same level has DatabaseInitializer.cs?
Would appreciate any help on this.
Many thank in advance
Fil
Hi All,
It is my first time installing IdentitySever on my QuickApp and I am using this link from Eben has a guide. However I am getting a error related with DbContext.
"InvalidOperationException: No database provider has been configured for this DbContext. A provider can be configured by overriding the DbContext.OnConfiguring method or by using AddDbContext on the application service provider. If AddDbContext is used, then also ensure that your DbContext type accepts a DbContextOptions<TContext> object in its constructor and passes it to the base constructor for DbContext."
This exception was generated at:
QuickApp.IdentityServerDbInitializer.SeedAsync() in IdentityServerDBInitializer.cs
I'm probably missing something from this part of the post:
"Note that we use the override keyword for our SeedAsync() method. That means we have to add the virtual keyword to our base implementation in the file DatabaseInitializer.cs ( i.e. virtual public async Task SeedAsync()).
Also we now have additional DbContexts in our solution (i.e. IdentityServer’s PersistedGrantDbContext and ConfigurationDbContext), so we need to modify the constructor of our own ApplicationDbContext class and restrict the parameter it can accept to the type DbContextOptions<ApplicationDbContext>, else dependency injection will pass in the wrong DbContextOptions that belongs to one of the other DbContext.
We do this by changing the line public ApplicationDbContext(DbContextOptions options) : base(options) to public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options)"
What I did was:
In DatabaseInitializer.cs
Change: public async Task SeedAsync()
to: virtual public async Task SeedAsync()
In ApplicationDbContext.cs
Changed: public ApplicationDbContext(DbContextOptions options) : base(options)
To: public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options)
Finally and not shore if this has any impact:
- I've placed the file IdentityServerDBInitializer.cs under the QuickApp folder at the same level as the startup.cs file is. Is this correct or should this be under the DAL project at the same level has DatabaseInitializer.cs?
Would appreciate any help on this.
Many thank in advance
Fil
Quote from Ingo on October 14, 2020, 10:33 amHi,
I would first try to bring the database up to date.
With add-migration VersxIf you do not use the template then note that the DBContext should look like this:
public class ApplicationDbContext : IdentityDbContext<ApplicationUser, ApplicationRole, string>
It must be derived from IdentityDbContext.
If you are using a current version, please note this link https://github.com/emonney/QuickApp/issues/160
Hi,
I would first try to bring the database up to date.
With add-migration Versx
If you do not use the template then note that the DBContext should look like this:
public class ApplicationDbContext : IdentityDbContext<ApplicationUser, ApplicationRole, string>
It must be derived from IdentityDbContext.
If you are using a current version, please note this link https://github.com/emonney/QuickApp/issues/160
Quote from filipedine on October 15, 2020, 10:18 pmHi Ingo,
Many thanks for you help. It seems I was also missing the libraries System.Reflection at startup.cs
and didn't have the connection string properly done.
Many thanks
Fil
Hi Ingo,
Many thanks for you help. It seems I was also missing the libraries System.Reflection at startup.cs
and didn't have the connection string properly done.
Many thanks
Fil
IMPORTANT!
This forum is now archived. Click here for the New Support Forum