gpt4 book ai didi

c# - ASP.NET Identity 检查自定义 UserValidator 实现中是否存在电子邮件

转载 作者:太空宇宙 更新时间:2023-11-03 15:05:18 30 4
gpt4 key购买 nike

在我的应用程序中,我创建了自定义版本的 UserValidator,以便我可以自己配置错误消息。

目前基本实现为found here ,但与其他资源文件引用。

我遇到的问题是在 ValidateEmailAsync 方法中。它包含以下行:

var email = await Manager.GetEmailStore().GetEmailAsync(user).WithCurrentCulture();

这给出了无法访问 GetEmailStore() 方法的错误,因为它是 UserManager 对象的内部方法。寻找解决办法,我找到了 this question ,建议改用这一行:

var email = await Manager.GetEmailAsync(user.Id).ConfigureAwait(false);

但是执行它会给出一个异常,它找不到任何具有给定 ID 的用户。

还有其他方法可以检索 IUser 对象的电子邮件属性吗?如果需要,here's my current code .

最佳答案

这样获取用户,然后抓取邮件;

var user = await Manager.GetUserAsync(User);
var email = user.Email;

关于c# - ASP.NET Identity 检查自定义 UserValidator 实现中是否存在电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43834454/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com