How to use sessions in an ASP.NET MVC 4 application?

后端 未结 5 1430
离开以前
离开以前 2020-11-22 17:02

I am new to ASP.NET MVC. I have used PHP before and it was easy to create a session and select user records based on the current session variables.

I have looked ev

5条回答
  •  心在旅途
    2020-11-22 17:37

    U can store any value in session like Session["FirstName"] = FirstNameTextBox.Text; but i will suggest u to take as static field in model assign value to it and u can access that field value any where in application. U don't need session. session should be avoided.

    public class Employee
    {
       public int UserId { get; set; }
       public string EmailAddress { get; set; }
       public static string FullName { get; set; }
    }
    

    on controller - Employee.FullName = "ABC"; Now u can access this full Name anywhere in application.

提交回复
热议问题