You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

调试ExternalLoginCallBack时触发IUserLockoutStore未实现异常

Fixing "Store does not implement IUserLockoutStore" Exception in ExternalLoginCallback

Let's break down exactly why this error is happening and walk through the fixes step by step:

Why This Error Occurs

The exception pops up because your SignInManager is trying to use user lockout logic (you enabled it in ApplicationUserManager with UserLockoutEnabledByDefault = true), but the UserStore linked to your UserManager doesn't implement the IUserLockoutStore interface.

Looking at your code, two key issues are driving this:

  1. Your RegistrationController's parameterless constructor manually creates a basic UserManager<ApplicationUser> instead of using the pre-configured ApplicationUserManager from the OWIN container. This basic manager doesn't have a lockout-aware store attached.
  2. The UserManager2 property in your controller has an infinite recursion bug (return UserManager2 ?? ...) which means it can't correctly fetch the proper ApplicationUserManager from OWIN.

Step-by-Step Fixes

1. Fix the Infinite Recursion in UserManager2

First, repair the broken UserManager2 property by referencing the private backing field instead of the property itself:

public ApplicationUserManager UserManager2 {
    get { return _userManager ?? HttpContext.GetOwinContext().GetUserManager<ApplicationUserManager>(); }
    private set { _userManager = value; }
}

2. Update RegistrationController Constructors to Use ApplicationUserManager

Replace your controller's constructors to pull the pre-configured ApplicationUserManager and ApplicationSignInManager from the OWIN container instead of manually creating them:

public RegistrationController() : this(
    HttpContext.Current.GetOwinContext().GetUserManager<ApplicationUserManager>(),
    HttpContext.Current.GetOwinContext().Get<ApplicationSignInManager>()
) { }

public RegistrationController(ApplicationUserManager userManager, ApplicationSignInManager signInManager) {
    UserManager2 = userManager;
    SignInManager = signInManager;
}

This ensures you're using the ApplicationUserManager you set up with lockout support, which uses a UserStore<ApplicationUser> that does implement IUserLockoutStore (since your ApplicationUser inherits from IdentityUser, which includes all required lockout properties).

3. Optional: Disable Lockout If You Don't Need It

If you don't actually want user lockout functionality, you can just turn it off in ApplicationUserManager.Create:

// Replace the existing lockout enable line with:
manager.UserLockoutEnabledByDefault = false;

This will prevent the SignInManager from trying to access lockout-related store methods entirely.

Verify the Fix

After making these changes, re-run your debug session. The SignInManager.ExternalSignInAsync call should execute without throwing the "Store does not implement IUserLockoutStore" exception.

内容的提问来源于stack exchange,提问作者Adem ZEINA

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 07:11:57