>
 





When developing Web applications with ASP.NET, you sometimes need to access data which is shared among users again and again throughout the life of the application.

If you want to share a value or an object instance between all sessions, you typically use the Application object. However, a better alternative to Application object is a static property defined in a class. Static properties maintain their values throughout the Application. So they work like the Application object.

Storing and reading a static value is faster when we compare it with the Application object because static variables do not need to look-up in a collection when you refer to them and you do not need to cast from object to a specific type.

The key reason that the Application object exists in ASP.NET is for compatibility with classic ASP code to allow easy migration of existing applications to ASP.NET.

Want automatic updates? Subscribe to our RSS feed or
Get Email Updates sent directly to your inbox!

Currently rated 5.0 by 3 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5


Comments

November 1. 2007 13:42

Isn't the cache object better? I mean if we need to access data for all users on a frequent basis, the cache is the answer...at least for me.

or is there any difference? cache will invalidate depedning on rules...so we take care the data isn't stale...which is logic we need to implement to some unknown object's static property...

steve.raynold | Reply

November 1. 2007 14:15

Application provides a place to store an Object that is scoped Application wide.  Once created this object will live for the duration of your app unless you destroy it.

Cache also provides application wide storage, but also provides for automatic expirations (to allow you to reclaim memory) and expiration callbacks.  When you are using Cache, your code should anticipate that the Cached object may have been automatically expired and thus may need to be recreated.

Blogging Developer | Reply

January 22. 2009 11:17

Pingback from keyongtech.com

Please help explain what an "application instance" really is in terms of static data | keyongtech

keyongtech.com | Reply

October 21. 2009 06:57

While your article mentions this, I think you should stress more strongly that static variables are shared by _sessions_ of a Web site. I've seen a many an otherwise well-informed rookie think that static variables are a voodoo escape hatch for per-user variable persistence. rp

Roger Pence | Reply

October 22. 2009 17:32

Social comments and analytics for this post

This post was mentioned on Twitter by bloggingdev: Static Variables vs Application Object - Boost ASP.NET Site Performance by Using Static Variables - http://su.pr/65oahz

uberVU - social comments | Reply

December 26. 2009 19:29

thanks!  very helpful post!! like the template btw ;)

cash loans | Reply

Add comment




(Will not be displayed!)








Free CMS