加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-identity – AspNet Identity使用相同的电子邮件进行多

发布时间:2020-12-16 03:23:52 所属栏目:asp.Net 来源:网络整理
导读:Visual Studio-为AspNet Identity生成一堆代码,即LoginController和ManageController.在ManageController中有以下代码: [HttpGet,Route("Manage/LinkLoginCallback")] public async TaskActionResult LinkLoginCallback(string returnUrl) { ExternalLoginI
Visual Studio-为AspNet Identity生成一堆代码,即LoginController和ManageController.在ManageController中有以下代码:

[HttpGet,Route("Manage/LinkLoginCallback")]
    public async Task<ActionResult> LinkLoginCallback(string returnUrl)
    {
        ExternalLoginInfo loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync(XsrfKey,User.Identity.GetUserId());

        ...
        var result = await UserManager.AddLoginAsync(User.Identity.GetUserId(),loginInfo.Login);

        if (result.Succeeded) 
        {
            ...
        }
    }

我对此代码的问题是,当添加了具有现有电子邮件地址的外部登录时,UserManager.AddLoginAsync()会引发异常.但是,这似乎是一个有效的场景:

>用户通过电子邮件注册Google Plus:user-email@gmail.com
>用户使用相同的电子邮件注册Facebook.
>现在,由于此例外,他们无法在我的应用程序中的单个本地帐户下“链接”这两个帐户.

如何处理这种情况并添加两个帐户?这样做有什么问题吗?

解决方法

您可以禁用此类唯一电子邮件的要求:

manager.UserValidator = new UserValidator<ApplicationUser>(manager)
        {
            RequireUniqueEmail = false
        };

其中manager是UserManager类的实例.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读