简体   繁体   中英

HttpContext.Current.Session[“UserID”] not null even Session[“UserID”] null after session timeout in asp.net

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

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 .

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM