2016-05-28 14 views
0

私はASP.NET MVCアプリケーションでFaceBookログインを実装しようとしています。それはSignInManager.ExternalSignInAsync(loginInfo, isPersistent: false)を実行しようとFacebookのログインがASP.NET MVCの失敗を返します

毎回、それはここではコード -

Startup.Auth.cs

app.UseFacebookAuthentication(
    appId: Social_NetworkBLL.FaceBook_AppID, 
    appSecret: Social_NetworkBLL.FaceBook_SecretID 
); 

AccountController

[HttpPost] 
[AllowAnonymous] 
[ValidateAntiForgeryToken] 
public ActionResult ExternalLogin(string provider, string returnUrl) 
{ 
    // Request a redirect to the external login provider 
    return new ChallengeResult(provider, Url.Action("ExternalLoginCallback", "Account", new { ReturnUrl = returnUrl })); 
} 

[AllowAnonymous] 
public async Task<ActionResult> ExternalLoginCallback(string returnUrl) 
{ 
    var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync(); 
    if (loginInfo == null) 
    { 
     return RedirectToAction("Login"); 
    } 

    // Sign in the user with this external login provider if the user already has a login 
    var result = await SignInManager.ExternalSignInAsync(loginInfo, isPersistent: false); 
    switch (result) 
    { 
     case SignInStatus.Success: 
      return RedirectToLocal(returnUrl); 
     case SignInStatus.LockedOut: 
      return View("Lockout"); 
     case SignInStatus.RequiresVerification: 
      return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = false }); 
     case SignInStatus.Failure: 
      return RedirectToAction("Login"); 
     default: 
      // If the user does not have an account, then prompt the user to create an account 
      ViewBag.ReturnUrl = returnUrl; 
      ViewBag.LoginProvider = loginInfo.Login.LoginProvider; 
      //return View("ExternalLoginConfirmation", new ExternalLoginConfirmationViewModel { Email = loginInfo.Email }); 

      ExternalLoginConfirmationViewModel vm = new ExternalLoginConfirmationViewModel { Email = loginInfo.Email }; 
      //return RedirectToAction("ExternalLoginConfirmation", new { model = vm, returnUrl = returnUrl }); 
      return await ExternalLoginConfirmation(vm, returnUrl); 
    } 
} 
Failure

を返します。

FBアプリの設定 enter image description here

答えて

1

SignInStatus.Failureユーザーが既にサイトに登録されているか否かを示します。デフォルトのASP.NET MVCアカウントコントローラのExernalLoginCallBackは次のようになります。あなたに

// 
     // GET: /Account/ExternalLoginCallback 
     [AllowAnonymous] 
     public async Task<ActionResult> ExternalLoginCallback(string returnUrl) 
     { 
      var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync(); 
      if (loginInfo == null) 
      { 
       return RedirectToAction("Login"); 
      } 

      // Sign in the user with this external login provider if the user already has a login 
      var result = await SignInManager.ExternalSignInAsync(loginInfo, isPersistent: false); 
      switch (result) 
      { 
       case SignInStatus.Success: 
        return RedirectToLocal(returnUrl); 
       case SignInStatus.LockedOut: 
        return View("Lockout"); 
       case SignInStatus.RequiresVerification: 
        return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = false }); 
       case SignInStatus.Failure: 
       default: 
        // If the user does not have an account, then prompt the user to create an account 
        ViewBag.ReturnUrl = returnUrl; 
        ViewBag.LoginProvider = loginInfo.Login.LoginProvider; 
        return View("ExternalLoginConfirmation", new ExternalLoginConfirmationViewModel { Email = loginInfo.Email }); 
      } 
     } 

あなたはRedirectToAction("Login");

を削除 Case SignInStatus.Failure.上のログインページにリダイレクトされ、上記のコード
関連する問題