I’m having some trouble recently.
On a WebForm I declare a static object, like this :
public static MyObject myobject=new MyObject();
Response.Write(myobject.Title());
now, if I load another page that doesn’t contain the declaration of myobject and I do again
Response.Write(myobject.Title());
I see the previosly result. Is the object stored on session during the navigation due to the static? And it’s reckon by the VIEWSTATE? Or what’s happening?
It’s just a static variable. It “lives” alongside the type – so it will be shared by all code accessing the same field via the same type in the same
AppDomain. It will be lost onAppDomainrecycle, and won’t be shared across multiple servers, etc.Basically it’s not a good idea to use
staticvariables in webapps other than occasionally for local caching…