I have to restore my LogIn Id textbox when user logs out from my mvc application, but in Logout action I am doing FormAuthentication.Signout() and then session.clear() and session.abandon() so when i logout i am not able to get the just now logged out user login Id.. how to get that user login id when he logs out?
Asked
Active
Viewed 884 times
1
-
See http://stackoverflow.com/questions/1064271/asp-net-mvc-set-custom-iidentity-or-iprincipal/1064345#1064345 – haim770 Oct 21 '13 at 12:06
-
Before Sign-out and Session clear, get that user id and store it some where. If you want to perform some action for User LogOff in Application, then it is better to perform that action before session clear. – 111 Oct 21 '13 at 13:32
2 Answers
2
You should save login in some other place, for example in cookie. Maybe even during initial login (not when logging out).
So when user logs in - you saves id into some cookie with "long" persistence (for several months may be), but not uses this cookie in any logic.
And if "later" you render a page without authenticated - you can check for a cookie and write cookie content into login box.
Dmitry
- 16,110
- 4
- 61
- 73
-
+1. to address security and privacy concerns, you should only do this is the user checks a "remember me on this computer" checkbox. – Mike Goodwin Oct 21 '13 at 13:30
1
If you just need the User Id to display the Login view once the user logout, just get the ID before deleting the session and do the logout.
Then, put it in TempData:
TempData["LastUserId"] = theId;
Then, you can redirect to the Login action... and inside the Login action you can have access to the User Id retrieving it from TempData:
var userId;
if(TempData["LastUserId"] != null){ //if the user is coming directly to login, it will be null.
userId = TempData["LastUserId"];
}
Romias
- 13,783
- 7
- 56
- 85