http://www.asp.net/mvc/tutorials/mvc-4/using-oauth-providers-with-mvc
我正在使用本教程中的代码(当然,不是全部)。一切都很完美,但当我尝试传递电子邮件时,我有System.Collections.Generic.KeyNotFoundException
。为什么?如何从Facebook传递电子邮件价值?
return View("ExternalLoginConfirmation", new RegisterExternalLoginModel {
UserName = result.UserName,
ExternalLoginData = loginData,
FullName = result.ExtraData["name"],
Email = result.ExtraData["email"],
ProfileLink = result.ExtraData["link"],
});
这有效:
return View("ExternalLoginConfirmation", new RegisterExternalLoginModel {
UserName = result.UserName,
ExternalLoginData = loginData,
FullName = result.ExtraData["name"],
//Email = result.ExtraData["email"],
ProfileLink = result.ExtraData["link"],
});
此致
答案 0 :(得分:0)
默认情况下,Facebook不会共享电子邮件地址。有关详细信息,请参阅this post,但您可以在为网站进行用户注册时将注册模式更改为要求发送电子邮件。此外,在尝试访问之前,您可以先检查集合是否具有密钥
AuthenticationResult result =
OAuthWebSecurity
.VerifyAuthentication(
Url.Action("ExternalLoginCallback", new { ReturnUrl = returnUrl }));
// Log in code
if (result.ExtraData.ContainsKey("email"))
// Use email