c# - Session variable does not maintain value across different controllers -


i working 2 controllers, both save value session 1 of controller manages maintain it's value.

the line of code saves value is

session["logindate"] = <datetimeobject>; 

and same in both controllers. second controller gets called first controller , while in second controller, if set value of session we're ok until in calling controller. if call first controller only, value can set , sent client.

i have tried modifying second config file include

<sessionstate mode="inproc" timeout="30" /> 

and have made sure @ same version of .net, mvc, etc...

any ideas how debug this? else should check?

update
there way pass session state different servers or usign cookies better since cookie on client browser? new discovery second controller an

redirect("serverofcontroller_1");

the controller gets initialised mvc core, has correct references context of current request. when create instance of controller yourself, won't have context @ all, can't use controller interface.

for method in controller work in context, can't rely on in controller interface. if want set session variable method, have current context , access session object that:

system.web.httpcontext.current.session["logindate"] = <datetimeobject>; 

you can copy controller context current controller after have created instance. way controller created have same context current controller. example:

secondcontroller second = new secondcontroller(); second.controllercontext = controllercontect; second.somemethod(); 

Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -