无法检索userID

时间:2016-01-01 00:28:26

标签: c# login

我尝试了所有不同的方法,但在成功登录后仍然无法检索当前的用户ID。没有错误返回。

下面是开箱即用的代码:

        // 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:
                Session["userID"] = User.Identity.GetUserId();  <---- here
                return RedirectToLocal(returnUrl);
            case SignInStatus.LockedOut:
                return View("Lockout");
            case SignInStatus.RequiresVerification:
                return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = false });
            case SignInStatus.Failure:
            default:

请帮忙。谢谢。

1 个答案:

答案 0 :(得分:0)

以下是我解决问题的方法:

           case SignInStatus.Success:
                ApplicationUser userid = UserManager.FindByEmail(loginInfo.Email);
                string UserId = userid.Id;