Last post May 22, 2017 11:51 AM by sbuggle
May 21, 2017 11:40 PM|sbuggle|LINK
What is the best way to retain the user.identity.Name for the current user along with email , employee number etc when users log in which will be many users obtaining the same form.
Currently putting the ling to sql results in Session['name"] = results.FullName
and so on ...when the post is done for this user set Session.Abandon();
May 22, 2017 05:16 AM|Zhi Lv - MSFT|LINK
According to your description, you store a string in the session, and also you could store an object in the session, look at the following code.
(1) create the class of user model:
public class User
public string Id
public string FullName
public string Email
public string EmployeeNumber
(2)After login succeed, you could create an instance of the user model, then store it in the session.
public void AfterLoginSucceed()
var user = new User
Email = "email@example.com",
EmployeeNumber = "0000001",
FullName = "Tom James",
Id = "1"
(3)You could get current user from the session such like this.
User currentUser = (User)Session["CurrentUser"];
when the post is done for this user set Session.Abandon();
If you doesn't call Session.Abandon() explicitly, it will be called automatically when session time out.
Session.Abandon() means that destroy all the values in the session and release their resources, and then begin a new session.
you could refer to the following link.
May 22, 2017 11:51 AM|sbuggle|LINK