[英]Custom UserConfirmation not being called in Asp.Net Core 5 Identity
Using Asp.Net Core 5.0 I am adding Identity and a custom UserConfirmation:使用 Asp.Net Core 5.0,我添加了 Identity 和自定义 UserConfirmation:
services
.AddIdentityCore<User>()
.AddEntityFrameworkStores<Context>()
.AddDefaultTokenProviders()
.AddUserConfirmation<UserConfirmation<User>>();
Where my custom UserConfirmation
is the following:我的自定义
UserConfirmation
如下:
public class UserConfirmation<T> : IUserConfirmation<T> where T : User {
public async virtual Task<Boolean> IsConfirmedAsync(UserManager<T> manager, T user) {
if (!user.Enabled)
return false;
if (!await manager.IsEmailConfirmedAsync(user))
return false;
return true;
}
}
However the method CanSignInAsync
:但是方法
CanSignInAsync
:
_signInManager.CanSignInAsync(user)
returns always true
even with user is not enabled.即使未启用用户,也始终返回
true
。
And the breakpoint I added in IsConfirmedAsync
is not being triggered.并且我在
IsConfirmedAsync
添加的断点没有被触发。
What am I missing?我错过了什么?
I found the problem.我发现了问题。 The following needs to be added to Identity options:
以下需要添加到身份选项中:
services.AddIdentityCore<User>(options => {
options.SignIn.RequireConfirmedAccount = true;
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.