Working with Session Variables in C#
I am pretty clear with the defination of session variables.But I have a
practical problem with session. I am having a view where I am using a
viewData and this viewdata is assigned a value from session variable. I
have this session variable placed in a controller. In the view I have
ViewData["MyView"]
In controller
if(Session["MySession")!=null)
{
ViewData["MyView"]=Session["MySession");
}
The above controller is common controller for each page. I mean from every
other page , the control is redirected to above controller . So ,
following this, I have three other controllers
Controller1 Controller2 Controller3
If I click on RunReport from Page One,Control goes to Controller1 and sets
a session variable
like Session["MySession"]=1;
after setting this Session, controller goes to common controller for
setting ViewData[MyView] and adding value to this viewdata has different
logic everytime.
Similary, when I click on Runreport from Page Two , control goes to
Controller2 and Sets a session variable
like Session["MySession"]=1;
after setting this Session, controller goes to common controller for
setting ViewData[MyView] and adding value to this viewdata has different
logic everytime. By this I mean to say ViewData will have different values
everytime.
Similary, when I click from Page Three, control behaves and everthing in
same manner.
Everything is working for now. But My problem is that I am using Same
session Variable in each different controller. Suppose User1 has opened
page1 and he clicks on runreport page , ofcourse this session variable
will have now a value and after this control will go to Common controller
and sets a value in view data. At the same time if another uses opens
page2 and he clicks on runreport , then on its click again this process
will be followed or the previous session will already have a value even If
I click on runreport or not. Actually I am totally confused. Please Help
Me. give some technically points of understanding sessions deeply at
practical level and please clear my point. Thank you very much.
No comments:
Post a Comment