Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET Application state vs a Static object

if i have a standard ASP.NET application, is there any difference between making an object static as opposed to putting the object instance in the Application state?

from my understanding, both objects exist ONCE for the app domain.

Secondly, what happens if you have a static object in a referenced dll, for an ASP.NET site. It's also part of the app domain, so it will always exist once?

like image 977
Pure.Krome Avatar asked Nov 19 '08 23:11

Pure.Krome


People also ask

What is ASP Net application state?

Application state is a data repository available to all classes in an ASP.NET application. Application state is stored in memory on the server and is faster than storing and retrieving information in a database.

What is session state and application state?

"Application state" = the state of the application, which is the same for all users. "Session State" = state specific to this particular user session. Each user has separate session state.


1 Answers

From: http://support.microsoft.com/default.aspx?scid=kb;en-us;Q312607

ASP.NET includes application state primarily for compatibility with classic ASP so that it is easier to migrate existing applications to ASP.NET. It is recommended that you store data in static members of the application class instead of in the Application object. This increases performance because you can access a static variable faster than you can access an item in the Application dictionary.

Also, yes, static variables behave the same way regardless of where they are loaded from, and exist exactly once per app domain (unless you're talking about those labeled [ThreadStatic])

like image 181
Chris Avatar answered Oct 01 '22 01:10

Chris