How does static objects behave in ASP.NET

  • Thread starter Thread starter Michael
  • Start date Start date
M

Michael

Hi,

I have a class with static fields. The values of those fields appear to
stick between Web requests. That behaviour is a bit of a surprise to me, as
I would expect the object to be completely destroyed between Web requests
(maybe not technically correct way of describing this, since the fields are
static, there is no object instantiation).

The static fields values do not seem to be shared between sessions though;
that's good.

Any additional info, or pointers to where I can read more about this on the
Net would be much welcomed.

Thanks.
 
Thanks for the info and links.


Scott Allen said:
I have a few articles on the topic:
You'll find those statics fields are shared across sessions, in fact
each web application will have only one instance of each static field,
so you have to be very careful how you use them in a web app.

I have a few articles on the topic:

Get a Charge From Statics with Seven Essential Programming Tips
http://msdn.microsoft.com/msdnmag/issues/05/01/StaticsinNET/default.aspx

Statics & Thread Safety: Part I
http://odetocode.com/Articles/313.aspx

Statics & Thread Safety: Part II
http://odetocode.com/Articles/314.aspx
 

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