Session state issue

G

Guest

Problem with sessions

I have created an application without concern for sessions. As it turns out
I think that might be my undoing.

What I have:
I have an online quiz.
I don’t need to know users or save any data. If the application crashes or
user exits the program they should simply start again. Pretty basic.
All interactions are stored in an array (not much going on to save to a
file) and that is that.

The problem:
All changes and interactions are being saved to the application state. So if
computer 1 changes values, it also changes values on computer 2. I don’t want
this. Furthermore, if I close the window and reopen it all the values are
still there which is why I suspect the values are being stored in application
state.

Am I going to have to re-design all my variables to be session state
variables?
 
D

Daniel Walzenbach

Sean,



application state is shared across every instance of your application
whereas session state is specific to one user. Application state lives as
long as your application lives, session state on the other hand lives only
as long as one session lives.



Example:



Assumption: Nobody ever logged on to your application



User 1 access your application

Events:

Application start (this is for the whole application. What you set
in here will be visible to all users)

Session Start (this is only for user 1 accessible)





User 2 access your application

Events:

Session Start (note that only session start fires. The application is
already running)





User 1 leaves your application.

Events:

Session End (This event fires after the session times out.
This duration is most prob. Set in your web.config. Usually this is 20min.
This event DOES NOT fire when the user closes the browser. Don't confuse
this)





User 3 logs on

Events:

Session Start (note that only session start fires. The application is
already running)





User 3 leaves your application.

Events:

Session End (This event fires after the session times out.
This duration is most prob. Set in your web.config. Usually this is 20min.
This event DOES NOT fire when the user closes the browser. Don't confuse
this)





User 2 leaves your application.

Events:

Session End (This event fires after the session times out.
This duration is most prob. Set in your web.config. Usually this is 20min.
This event DOES NOT fire when the user closes the browser. Don't confuse
this)





Events

ApplicationEnd (This event depends on your settings. After some
time when nobody is accessing your application the application shuts down.
Application state is lost)



Does this help? Have a little background reading at

http://www.msdn.microsoft.com/asp.n...l/scalenetchapt06.asp#scalenetchapt06_topic16



Best regards



Daniel Walzenbach
 
G

Guest

This much I know.

What I dont know is why code behind variables default as application state.
Or perhaps its becuase I decared them as Static but they will not work
otherwise.

Have any insight to this?
 
H

Hans Kesting

This much I know.
What I dont know is why code behind variables default as application state.
Or perhaps its becuase I decared them as Static but they will not work
otherwise.

Have any insight to this?

Static variables are defined at *application* level. Remember: an
asp.net application is a *single* application, serving *multiple*
concurrent users. This in contrast to a "winform" application, where
every user has his/her own application.

Hans Kesting
 
M

Morten Wennevik

Static variables are shared across the application. If you can't use non static variables, see if you have any static methods using these variables? Are these methods supposed to be static?
 
G

Guest

I found out late last night that I will indeed have to do session variables
for these static issues. So I am currently working on "sessionbag" which I
think will go fine at least at this point.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top