C# Session Variables and Static Variables

Started by rcallicotte, June 23, 2008, 12:43:00 pm

Previous topic - Next topic


If anyone out there knows anything about web programming with C#, do you know if a static variable can be accessed across sessions by default.  In other words, two people are accessing the web page that is using static variables.  Will the sessions isolate the static variables on both pages unique to each user or is there a danger that the static variables will cross over the sessions? 

The way I understand it, the session states are unique to the user, include the static variable data.
So this is Disney World.  Can we live here?


Quote from: calico on June 23, 2008, 12:43:00 pm
web programming with C#

Ah, see, there's your problem.

::) ;D

Some solutions include:

Sorry, but C# doesn't make sense to me in this context.  If you need the performance that C# offers over these languages, it would almost be a better idea just to write the program in C as a desktop application (which would be faster) and write some kind of script to grab user input from the internet and launch the C program with the parameters you're given.

To answer your question, though, I know for a fact that PHP creates separate instances of static variables, and would expect the same to be true of C# as well.
http://www.terragen.org - A great Terragen resource with models, contests, galleries, and forums.


Thanks, o_b.  Don't have a choice right now.

The problem with C# is that static variables are alive as long as the application domain (AppDomain) is up or as long as the code on the page is not updated.  This means if I do -

static string strWow = "TG2 Rules the World"

In this case, the string strWow will keep this value potentially forever.  C# has a problem in this regard.  Clearly.  Anyway, what I need to understand is if this is true across sessions, which is in a completely different level in the OSI layers than the Presentation or Application.
So this is Disney World.  Can we live here?


Do a test? Use two different browsers at the same time, that should give you two different sessions, so you'll be able to figure out by yourself... No?


@Rhalph, yes.  I'm working on that.  But, I was hoping somewhere Microsoft had clarified this important hole.   ;D
So this is Disney World.  Can we live here?


The world is round... so you have to use spherical projection.


June 23, 2008, 05:32:44 pm #6 Last Edit: June 23, 2008, 08:28:57 pm by calico
Point taken.  Excuse me while I throw up from nervous tension.   

Quote from: Will on June 23, 2008, 04:03:09 pm
when is Microsoft clear on anything?
So this is Disney World.  Can we live here?