While deploy an asp.net mvc 3 project, I got the issue recently which I have no idea why it happened.
I have a class named LoginSesion which will get the Authenticated User when user login and store in session.
public static LoginSession AuthenticatedUser
{
get
{
if (HttpContext.Current.Session["LoginSession"] != null)
return HttpContext.Current.Session["LoginSession"] as LoginSession;
return null;
}
set
{
HttpContext.Current.Session["LoginSession"] = value;
}
}
When I run the project, try to redirect user to a specific URL (e.g. http://localhost/user/details/1
), the HttpContext.Current.Session["LoginSession"] come to Null and redirect user back to Login page.
The weird thing is this does not always null, just sometimes. And when server runs too slow, it happens too although the session has not expire yet.
I have set in the web.config the session timeout as follow:
<authentication mode="Forms">
<forms loginUrl="~/UserProfiles/Logon" timeout="2880" />
</authentication>
and
<sessionState mode="InProc" timeout="2880" />
I'm using IIS 7.x for publishing and testing.