Issue with public variables

  • Thread starter Thread starter rk2008
  • Start date Start date
R

rk2008

I have an ASP.NET application, which needs to initialize a memory
location and update it multiple times in different projects in the same
solution. I have used a public static variable and I could achive what
I want. The problem is when User1 opens the application and starts
updating the variable, and User2 opens the application from a
different machine and tries to modify the value in the public variable,
User1's value is being affected. How do I overcome this?
Thanks in advance!
 
If each user has a different value for this variable, then clearly using a
static variable is not the way to go. Static variables should only be used
for system wide settings. Not for user specific settings.

You need to store user specific settings in session or via another user
specific mechanism.
 
Thanks for the response, Marina. I mentioned it as a variable but it's
actually an object, which I cannot put in a Session variable. Can you
give examples of "user specific mechanism" you mentioned.
Thanks
 
I have an object at my blog. to handle storing objects. (I'm not sure if
this is what you're asking about or not)

You could easily copy and modify it to have a Session Store, or an
Application Store.


http://sholliday.spaces.msn.com/
10/24/2005 Entry


Web Session Wrapper for storing and retrieving objects
 
You can put objects in Session if it is in memory session, or serializable.

I think other user specific mechanism would be storing it in the Application
object by session, or rolling your own session - which all really amounts to
the same thing when you want to store user specific values on the server.
 
any particular reason you can't store this in the session ?
it sounds like you are saying that objects in general can't be stored in the
session which is just plain wrong.
 
Thank you! hope you answer another small question. In my solution, I
have a Web project and a Class library project. How do I access Session
variables in Class library project, which are set in Web project?
Thanks in advance!
 
System.Web.HttpContext.Current.Session

Thank you! hope you answer another small question. In my solution, I
have a Web project and a Class library project. How do I access Session
variables in Class library project, which are set in Web project?
Thanks in advance!
 

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

Back
Top