Using Dictionaries to Partition the Session Namespace

When used indiscriminately, the Session object is no better than a global data area. For large Web applications, the Session collection can become quite cluttered, increasing the likelihood that some part of the application can inadvertently make changes that have unexpected repercussions elsewhere. To avoid this situation, development teams must either use a naming convention that will decrease the chance of duplicate Session key names, or use other methods of storing session values.

One such method uses the Dictionary object to further partition the global session namespace. Like the Session object, the Dictionary object can store any number of values and keywords in an associative array. Disparate sections of the application can create individual Dictionary objects as necessary to contain local values, and store a single reference to their namespace in the Session object. Not only can groups of values be managed as a single entity, but the Dictionary object also makes it easy to free resources all at once when they are no longer required by the application. For more information on the Dictionary object, see the Microsoft Internet Information Server online product documentation.