Session variables are already available in your controller's constructor call .
But those Sesison[] variables are not freely available anywhere in your controller class.
-> You need to call them either in the constructor or in the method of your controller.
In addition, these variables had to be set somewhere, or their values would remain null .
According to your example, you need to set the Session["SessionClass"] key somewhere before calling it in the constructor:
public ActionResult Details() { Session["SessionClass"] = new MyClass() {
Now we will undo this saved value from the session:
public HomeController() { MyClass test = (MyClass)Session["SessionClass"];
This should work fine in your controller.
Greetings
source share