Click here to Skip to main content
15,897,371 members
Articles / Web Development / HTML

C# ViewState Management/Storage - Four Locations!

Rate me:
Please Sign up or sign in to vote.
4.30/5 (7 votes)
5 Nov 20075 min read 51.7K   28  
In this article, I discuss the PageStatePersister, and detail ViewState storage in one of four locations: Session, Application, AppGlobals, and server Cache.
using System;
using System.Collections;
namespace StaticAppGlobals
{
    public class AppGlobal
    {
        private static volatile AppGlobal instance = null;
        private static object syncRoot = new object();
        // make the default constructor private, we never
        // explicitly create an instance with "new"
        private AppGlobal()
        {
        }
        // public property that gets the single instance of this class.
        public static AppGlobal Instance
        {
            get
            {
                // only create a new instance if one doesn't already exist.
                if (instance == null)
                {
                    // use lock to ensure that only one thread can access
                    // this block of code at once. You can invoke lock on anything,
                    // syncRoot is just a convenience object instance.
                    lock (syncRoot)
                    {
                        if (instance == null)
                            instance = new AppGlobal();
                    }
                }
                return instance;
            }
        }
        private static string mySampleProperty = String.Empty;
        public static string MySampleProperty
        {
            get { return mySampleProperty; }
            set { mySampleProperty = value; }
        }

        public static Hashtable MySettings = new Hashtable();
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Systems Engineer
United States United States
I am a technical architect/senior software engineer, technical trainer, entrepreneur.

I have worked in several sectors from healthcare, to entertainment and global intelligent traffic systems, using .Net, SQL, NoSQL and some of the latest technologies to deliver quality software systems for clients.

Past tech flavors include C#, WCF, SOA, MVC, MVVM, Silverlight, Assembler, Pascal, VB, Java/J2EE/EJB/JDBC, Perl, NLTK, TSQL, NoSQL, KendoUI, NodeJS, SignalR, Backbone JS, Angular JS, Latest .Net technologies, Amazon AWS...

Comments and Discussions