首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MVC 5模板不使用OAuth

MVC 5模板不使用OAuth
EN

Stack Overflow用户
提问于 2016-01-29 21:03:48
回答 1查看 140关注 0票数 0

当我尝试在mvc模板应用程序中使用fb/g+登录时,它成功地登录,但当我注销并重新登录时,它再次带我到外部回调页面,而不是将我登录到应用程序中。已经试过很多次了,但都想不出来。任何帮助都是非常感谢的。

这是我的下一个登录方法-

代码语言:javascript
复制
[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 });
        }
    }

    //
    // POST: /Account/ExternalLoginConfirmation
    [HttpPost]
    [AllowAnonymous]
    [ValidateAntiForgeryToken]
    public async Task<ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl)
    {
        if (User.Identity.IsAuthenticated)
        {
            return RedirectToAction("Index", "Manage");
        }

        if (ModelState.IsValid)
        {
            // Get the information about the user from the external login provider
            var info = await AuthenticationManager.GetExternalLoginInfoAsync();
            if (info == null)
            {
                return View("ExternalLoginFailure");
            }

            var user = new ApplicationUser
            {
                UserName = model.Email,
                Email = model.Email,
                DateOfRegistration = DateTime.Now,
                DisplayName = model.DisplayName
            };
            var result = await UserManager.CreateAsync(user);
            if (result.Succeeded)
            {
                result = await UserManager.AddLoginAsync(user.Id, info.Login);
                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);
                    return RedirectToLocal(returnUrl);
                }
            }
            AddErrors(result);
        }

        ViewBag.ReturnUrl = returnUrl;
        return View(model);
    }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-01-30 05:32:51

刚刚从AspNetUserLogins中删除了数据,现在一切正常。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35094023

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档