Matías Fidemraizer
Matías Fidemraizer

Reputation: 64923

Configure a custom store in ASP.NET Identity 2.x

I've already developed an implementation to the following ASP.NET Identity interfaces: IUserLoginStore<TUser>, IUserClaimStore<TUser>, IUserRoleStore<TUser>, IUserPasswordStore<TUser>, IUserSecurityStampStore<TUser>.

Furthermore, I'm using OWIN/Katana, so I need to configure this by code during startup.

How do I provide/configure my custom store implementation to ASP.NET Identity?

Note: I've been searching a simple and clear tutorial on how to achieve this and I can't find one.

Upvotes: 0

Views: 315

Answers (1)

Anders Abel
Anders Abel

Reputation: 69260

In the default code created in an MVC 5.2 application, the identity configuration is done in App_Start\IdentityConfiguration.cs.

To use your own store instead of the default one, change the first line in the ApplicationUserManager.Create() method. By default it is

var manager = new ApplicationUserManager(
  new UserStore<ApplicationUser>(context.Get<ApplicationDbContext>()));

By changing it, you can inject your own IUserStore implementation.

If you also want to change the ApplicationUser type to use your own (or to simply rename ApplicationUser to something more suitable, that is done by changing the generic argument to ApplicationUserManager

public class ApplicationUserManager : UserManager<ApplicationUser>

Upvotes: 1

Related Questions