1
votes

i have set Session["UserID"] on page load. like

if(!IsPostBack) {
   Session["UserID"] = 1222;
}

I am using HttpContext.Current.Session["UserID"] to verify user session timeout or not.

My web config setting like this,

<sessionState mode="InProc" cookieless="false" timeout="20"/> 

After 20 minute Session["UserID"] object is null, but at same time, if i verify the HttpContext.Current.Session["UserID"] it show user id.

Please let me know how HttpContext.Current.Session["UserID"] is null after session timeout

2

2 Answers

0
votes

The Session property of the System.Web.UI.Page and System.Web.UI.UserControl classes is a reference to HttpContext.Current.Session.

You refer to session["UserId"] (note lower-case 's') - but you don't say what this is referencing. Presumably it's defined in your own code, and isn't referencing HttpContext.Current.Session.

0
votes

Please check you have set session value in custom controller base or derived class.

As an example if you check session value for session expired redirection at ActionFilterAttribute. please make sure your controller inherited calls have not existed session set methods.

because before calling to controller action method, controller constructor will be called.

I believe this will be helpful someone