0

I use external providers for Logging, and I need to setup some user data immediately after user logged in.

Class AccountController has method ExternalLoginCallback, but after successful SignIn, I can't get UserId. (Method User.Identity.GetUserId() return NULL - I read somewhere that redirect is needed after SignIn fo fill User.Identity).

Is here another way to get logged User Id immediately after signIn - without redirect?

Igor
  • 381
  • 3
  • 17
  • exact duplicate of this question: http://stackoverflow.com/questions/27940804/get-current-user-after-signinstatus-success from about the same time – trailmax Jan 14 '15 at 14:06

1 Answers1

0

This is an old post but I hope it helps someone having the same issue...

My application required redirection to different pages depending on the role of the logged in user, however, the Identity didn't update until the redirect completed after login/logout and the controller reloaded.

Here's how I got around it:

  1. Added a Method into the base controller which all my controllers inherit from and managed the redirect by Role
  2. Added an anonymous action in the Home Controller
  3. Redirected to this action from login and logout actions within the account controller.
  4. Called the method I created in #1 and returned RedirectToActionResult from the dummy action.

Because the controller got the chance to reload, both the user and role objects refreshed correctly and the redirect worked.

This causes an unnoticeable flash but everything works.

Hope this helps.

Emre
  • 1