Keep track of Session value

A

Alan Wang

Hi there,

Once my application gets complicated and complicated. I found it's really
hard to keep track of Session value I am using in my asp.net application. I
am just wondering if anyone have any experience on how to keep track of
session value. Any help it's appreciated.

Thanks

Alan
 
P

Peter Rilling

This is really not an answer to your questions, but you might want to
refactor the code design.

Session variables are nothing more than "fancy" global variables. And just
like the way you might avoid the use of global variables in a normal
application, the same reasoning should be applied to session variables.
That is not to say that global/session variables are not important -- they
have their place -- but it is important to be able to rationalize why you
use them rather than just saying something like "they are convenient."

Having said that, here is my take on your question.

What do you mean "keep track of"? Do you mean being able to know what parts
of code are setting a particular variable or simply that you want a list of
session variables in use? In the past, if I wanted to use session
variables, I have often encapsulated the getting and setting behind some
other class that centralizes the action. Essentially there would then be
only one place in the entire code that sets or gets the value directly from
the session (that is there was only one call to Session["..."]). By doing
this, you can 1) centralize access to the variable, 2) be able to group
related session variables together, and 3) Be able to enforce consistency
like suppose that variable "foo" could only be set if variable "bar" is
null, then properties could help enforce that.
 
A

Alan Wang

Do you mean being able to know what parts
of code are setting a particular variable or simply that you want a list of
session variables in use?

Probably both. Sometimes I just lost keep track of where I used this Session
variable and why use this session variable especially when you didn't touch
that code for a while. For regular variable, I can use "go to definition"
and then be able to find where I defined this variable and data type. But I
can't do it with Session variable. That's something really bothers me. Do
you have any solution or suggestions for that.

Thanks in advanced

Alan



Peter Rilling said:
This is really not an answer to your questions, but you might want to
refactor the code design.

Session variables are nothing more than "fancy" global variables. And
just like the way you might avoid the use of global variables in a normal
application, the same reasoning should be applied to session variables.
That is not to say that global/session variables are not important -- they
have their place -- but it is important to be able to rationalize why you
use them rather than just saying something like "they are convenient."

Having said that, here is my take on your question.

What do you mean "keep track of"? Do you mean being able to know what
parts of code are setting a particular variable or simply that you want a
list of session variables in use? In the past, if I wanted to use session
variables, I have often encapsulated the getting and setting behind some
other class that centralizes the action. Essentially there would then be
only one place in the entire code that sets or gets the value directly
from the session (that is there was only one call to Session["..."]). By
doing this, you can 1) centralize access to the variable, 2) be able to
group related session variables together, and 3) Be able to enforce
consistency like suppose that variable "foo" could only be set if variable
"bar" is null, then properties could help enforce that.

Alan Wang said:
Hi there,

Once my application gets complicated and complicated. I found it's really
hard to keep track of Session value I am using in my asp.net application.
I am just wondering if anyone have any experience on how to keep track
of session value. Any help it's appreciated.

Thanks

Alan
 
P

Peter Rilling

When I need to find session variables, I simply search the whole project for
the string "session[". Then I catalog all the variables that I find and
where they are accessed.

Alan Wang said:
of code are setting a particular variable or simply that you want a list
of
session variables in use?

Probably both. Sometimes I just lost keep track of where I used this
Session
variable and why use this session variable especially when you didn't
touch
that code for a while. For regular variable, I can use "go to definition"
and then be able to find where I defined this variable and data type. But
I
can't do it with Session variable. That's something really bothers me. Do
you have any solution or suggestions for that.

Thanks in advanced

Alan



Peter Rilling said:
This is really not an answer to your questions, but you might want to
refactor the code design.

Session variables are nothing more than "fancy" global variables. And
just like the way you might avoid the use of global variables in a normal
application, the same reasoning should be applied to session variables.
That is not to say that global/session variables are not important --
they have their place -- but it is important to be able to rationalize
why you use them rather than just saying something like "they are
convenient."

Having said that, here is my take on your question.

What do you mean "keep track of"? Do you mean being able to know what
parts of code are setting a particular variable or simply that you want a
list of session variables in use? In the past, if I wanted to use
session variables, I have often encapsulated the getting and setting
behind some other class that centralizes the action. Essentially there
would then be only one place in the entire code that sets or gets the
value directly from the session (that is there was only one call to
Session["..."]). By doing this, you can 1) centralize access to the
variable, 2) be able to group related session variables together, and 3)
Be able to enforce consistency like suppose that variable "foo" could
only be set if variable "bar" is null, then properties could help enforce
that.

Alan Wang said:
Hi there,

Once my application gets complicated and complicated. I found it's
really hard to keep track of Session value I am using in my asp.net
application. I am just wondering if anyone have any experience on how
to keep track of session value. Any help it's appreciated.

Thanks

Alan
 

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

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top