ASP.NET Core Identity中UserManager何时不支持账户锁定?
Absolutely! There are definitely scenarios where UserManager.SupportsUserLockout returns false instead of the true you're seeing now. Here are the most common cases:
Custom User Stores Without Lockout Implementation
If you build a custom user store (instead of relying on the default Entity Framework Core store) and don't implement theIUserLockoutStore<TUser>interface,UserManagerwon't support account lockout. This interface defines all the required methods and properties for handling lockout-related data—thinkLockoutEnd,AccessFailedCount, andIsLockoutEnabled. Skip implementing this interface, andSupportsUserLockoutwill automatically returnfalse.Third-Party User Store Providers
Some third-party identity providers or custom storage solutions (like those for NoSQL databases, LDAP, or legacy systems) might not include lockout support out of the box. If their underlying store doesn't implementIUserLockoutStore<TUser>,UserManager.SupportsUserLockoutwill befalse.Intentional Disabling of Lockout
If your application has no use for account lockout functionality, you might intentionally skip implementing the lockout interface in your custom store to keep your data model and logic lean. Even with the default EF store, while it's enabled by default, you could technically remove the lockout-related properties from your user class and skip configuring lockout, though this is less common.
One important note: If you try to call lockout-specific methods (like SetLockoutEndDateAsync or IncrementAccessFailedCountAsync) when SupportsUserLockout is false, UserManager will throw a NotSupportedException. So it's always a good practice to check this property first before working with lockout features!
内容的提问来源于stack exchange,提问作者lonix

