2016-01-31 50 views
2

有點卡住這是怎麼發生的,但我目前已啓用Google和Facebook外部登錄到我乾淨的MVC5項目。當你登錄使用外部登錄,但是當你試圖將一個帳戶從Manage/ManageLogins在任的2個按鈕的鏈接,然後點擊我得到這個錯誤VS2015 MVC5默認模板,管理外部登錄錯誤?

Error Screen

一切正常

沒有修改任何代碼除了加入谷歌/ Facebook的整合繼ASP.NET

教程從ManageController

默認代碼,如果有人有興趣

// 
    // GET: /Manage/ManageLogins 
    public async Task<ActionResult> ManageLogins(ManageMessageId? message) 
    { 
     ViewBag.StatusMessage = 
      message == ManageMessageId.RemoveLoginSuccess ? "The external login was removed." 
      : message == ManageMessageId.Error ? "An error has occurred." 
      : ""; 
     var user = await UserManager.FindByIdAsync(User.Identity.GetUserId()); 
     if (user == null) 
     { 
      return View("Error"); 
     } 
     var userLogins = await UserManager.GetLoginsAsync(User.Identity.GetUserId()); 
     var otherLogins = AuthenticationManager.GetExternalAuthenticationTypes().Where(auth => userLogins.All(ul => auth.AuthenticationType != ul.LoginProvider)).ToList(); 
     ViewBag.ShowRemoveButton = user.PasswordHash != null || userLogins.Count > 1; 
     return View(new ManageLoginsViewModel 
     { 
      CurrentLogins = userLogins, 
      OtherLogins = otherLogins 
     }); 
    } 

    // 
    // POST: /Manage/LinkLogin 
    [HttpPost] 
    [ValidateAntiForgeryToken] 
    public ActionResult LinkLogin(string provider) 
    { 
     // Request a redirect to the external login provider to link a login for the current user 
     return new AccountController.ChallengeResult(provider, Url.Action("LinkLoginCallback", "Manage"), User.Identity.GetUserId()); 
    } 

    // 
    // GET: /Manage/LinkLoginCallback 
    public async Task<ActionResult> LinkLoginCallback() 
    { 
     var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync(XsrfKey, User.Identity.GetUserId()); 
     if (loginInfo == null) 
     { 
      return RedirectToAction("ManageLogins", new { Message = ManageMessageId.Error }); 
     } 
     var result = await UserManager.AddLoginAsync(User.Identity.GetUserId(), loginInfo.Login); 
     return result.Succeeded ? RedirectToAction("ManageLogins") : RedirectToAction("ManageLogins", new { Message = ManageMessageId.Error }); 
    } 

回答

0

K通過在LinkLoginCallBack()的最後一行放置一個斷點,我發現調試後出現了什麼問題,您可以深入地看到結果錯誤。對我來說,這是因爲我登錄的OAuth帳戶已經綁定到應用程序用戶

希望這可以幫助其他人誰也有同樣的問題