Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a global Value in an ASP.NET MVC website be accessed by any person using the site or is it instanced for each session? [duplicate]

I'm adding some new functionality to an MVC4 site. I have just added a global static class and a global variable to hold a value in which is determined at some point during a users visit to the site and will be used as a condition later on.

The thought then occurred to me that I was unsure of just how global a static value is in this context.

Do I have to specify the global value as a session variable?

Or will each user to the site get access to it in their own session anyway and I don't have to worry about one user setting it to one value and another user having access to this set value.

like image 219
BenM Avatar asked Sep 10 '13 12:09

BenM


1 Answers

Your basic question: Are static globals shared among all users?

Because each MVC site is an application, all statics are shared among your app's user pool.

Deeper Question: How do I store user data for the user's entire stay?

Your question about statics will earn you sneers from some and appreciation from others. Sneers because you could look this up, appreciation because your underlying question on storing user data for easy retrieval is an important one most of us have faced.

  • You already used a session. Sessions are awkward. They expire. They're particularly unreliable when you use load balancing. To deal with expired sessions, I've used action filters; The action filter checks for null session variable OnActionExecuting, re-populating the session if it is NULL.

  • I've had more success with cookies. Cookies have their own issues. Some client browsers don't support them. But cookies are accepted more and more often. The objections become less common.

like image 177
Dave Alperovich Avatar answered Oct 14 '22 10:10

Dave Alperovich