Answer the question
In order to leave comments, you need to log in
How to get stored value in ASP.NET MVC 4 session?
In one of the controller methods, I set the session value:
In another controller method, I try to get the value:
Null gets into the test variable. Tried HttpContext.Session same thing.
Of course, the user first passes through the first method of the controller, then through the second method.
If you get the value of the session in the first method of the controller, immediately after the recording, then the value is there. Works fine. But in the second method of the controller it seems to be absent. Session["User.Project"] = "Привет";
string test = Session["User.Project"];
Answer the question
In order to leave comments, you need to log in
var context = HttpContext.Current
context.Session["user_id"] = id;
var id = (int) context.Session["user_id"];
string test = Session["User.Project"];
It won't compile? Session returns an object, not a string.
We need to check the code for Session.Clear() or any other session state changes.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question