I have got some class
public static class SessionManager
{
public static UserSession UserSession
{
set
{
HttpContext.Current.Session["USER_SESSION"] = value;
}
get
{
UserSession userSession = new UserSession();
try
{
userSession = (UserSession)HttpContext.Current.Session["USER_SESSION"];
}
catch (Exception)
{
}
return userSession;
}
}
}
And I am trying to use it
var userSession = SessionManager.UserSession;
And the userSesssion is always null.
Any clue how it can be fixed?
I think the pattern you’re actually looking for in your property looks more like this:
(I only broke out
var session = HttpContext.Current.Session;so it would all fit nicely in StackOverflow.)