Visual Studio-generates a bunch of code for AspNet Identity, namely the LoginController and ManageController. In the ManageController there is the following code:
[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)
{
...
}
}
The problem I'm having with this code is that UserManager.AddLoginAsync()
throws an exception when an external login with an existing email address is added. However, this seems to be a valid scenario:
How do I handle this situation and add both accounts? Are there any problems with doing this?
You can disable the requirement for unique email like this:
manager.UserValidator = new UserValidator<ApplicationUser>(manager)
{
RequireUniqueEmail = false
};
Where manager
is an instance of UserManager class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With