ASP.net Identity Custom Tables Using OwinContext

I am trying to implement custom tables to store users / roles, etc. in the SQL server database using Entity framework 6.

I created a basic DbContext that comes from IdentityDbContext

public class MainContext : IdentityDbContext<ApplicationUser> { public MainContext() : base("name=Main") { } public static MainContext Create() { return new MainContext(); } } 

I also have a custom class that inherits IdentityUser

 public class ServiceUser : IdentityUser{ } 

In ConfigureAuth, the defualt code was:

 public void ConfigureAuth(IAppBuilder app) { app.CreatePerOwinContext(ApplicationDbContext.Create); app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create); app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create); .. } 

I want to use my MainContext here instead of ApplicationDBContext when I try the following

 app.CreatePerOwinContext(MainContext.Create()); 

I get an error

'Type arguments for the Owin.AppBuilderExtensions.CreatePerOwinContext (Owin.IAppBuilder, System.Func)' method cannot be taken out of use. Try to specify the type arguments explicitly.

Given that the default ApplicationDbContext looks like this:

 public class ApplicationDbContext : IdentityDbContext<ApplicationUser> { public ApplicationDbContext() : base("Main", throwIfV1Schema: false) { } public static ApplicationDbContext Create() { return new ApplicationDbContext(); } } 

I do not see what could be causing this error?

0
source share
2 answers

Stupid mistake, it should have been

 app.CreatePerOwinContext(MainContext.Create); 

but not

 app.CreatePerOwinContext(MainContext.Create()); 
0
source

Try

 app.CreatePerOwinContext<IdentityDbContext>(MainContext.Create); 
+4
source

All Articles