Different Session timeout for ASP.NET Identity 2.0 and normal sessions -
i'm using asp.net mvc 5 identity 2.0. i've set identity session timeout in startup.cs below:
app.usecookieauthentication(new cookieauthenticationoptions { authenticationtype = defaultauthenticationtypes.applicationcookie, loginpath = new pathstring("/login"), expiretimespan = timespan.fromminutes(double.parse(configurationmanager.appsettings["app:sessiontimeout"])) });
i think timeout set asp.net auth cookie. so, i've changed session timeout other sessions in global.asax below:
protected void session_start() { session.timeout = int.parse(configurationmanager.appsettings["app:sessiontimeout"]); }
i'm using following code login logic (note session variable @ end):
var usermanager = new usermanager(); var identityuser = await usermanager.findbyidasync(userid); var identity = await usermanager.createidentityasync(identityuser, defaultauthenticationtypes.applicationcookie); var authenticationmanager = httpcontext.current.getowincontext().authentication; authenticationmanager.signout(defaultauthenticationtypes.externalcookie); authenticationmanager.signin(new authenticationproperties() { ispersistent = ispersistent }, identity); session["mycustomsession"] = "mycustomdata";
this problem: after login , period of time, user.identity.isauthenticated
returns true, user.identity.getuserid()
returns user's id, while session["mycustomdata"]
returns null. seems owin session , custom session timeout not synced. do make them synced?
Comments
Post a Comment