0

I tried all different ways but still couldn't not retrieve the current userID after a successful login. No errors returned.

Below is the code out of the box:

        // 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:

Please help out. Thank you.

dailyUnknown
  • 152
  • 12
  • In the debugger, what is returned and stored in `result`? Is that what you are expecting or not? – James Kirsch Jan 01 '16 at 00:30
  • In that case, I suggest making sure whatever `loginInfo` is what you'd expect as well, check that through the debugger, you may have to back track until you find the source of the error. Otherwise I think you'd get the default case on switch – James Kirsch Jan 01 '16 at 22:03
  • Thank you JK. I found the answer via the post below: http://stackoverflow.com/questions/25439275/asp-net-identity-user-identity-getuserid-is-always-null-and-user-identity-is – dailyUnknown Jan 01 '16 at 22:49

1 Answers1

0

Below is how I resolved my issue:

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