ISessionStateItemCollection Interface

Definition

Defines the contract for the collection used by ASP.NET session state to manage session.

C#
public interface ISessionStateItemCollection : System.Collections.ICollection
Derived
Implements

Examples

The following code example implements the ISessionStateItemCollection and uses the SortedList class to store session-state variable names and values.

C#
using System;
using System.Web;
using System.Web.SessionState;
using System.Collections;
using System.Collections.Specialized;

namespace Samples.AspNet.Session
{

  public class MySessionStateItemCollection : ISessionStateItemCollection
  {
    private SortedList pItems = new SortedList();
    private bool pDirty = false;

    public bool Dirty
    {
      get { return pDirty; }
      set { pDirty = value; }
    }

    public object this[int index]
    {
      get { return pItems[index]; }
      set
      {
        pItems[index] = value;
        pDirty = true;
      }
    }

    public object this[string name]
    {
      get { return pItems[name]; }
      set
      {
        pItems[name] = value;
        pDirty = true;
      }
    }

    public NameObjectCollectionBase.KeysCollection Keys
    {
      get { return (NameObjectCollectionBase.KeysCollection)pItems.Keys; }
    }

    public int Count
    {
      get { return pItems.Count; }
    }

    public Object SyncRoot
    {
      get { return this; }
    }

    public bool IsSynchronized
    {
      get { return false; }
    }

    public IEnumerator GetEnumerator()
    {
      return pItems.GetEnumerator(); 
    }

    public void Clear()
    {
      pItems.Clear();
      pDirty = true;
    }

    public void Remove(string name)
    {
      pItems.Remove(name);
      pDirty = true;
    }

    public void RemoveAt(int index)
    {
      if (index < 0 || index >= this.Count)
        throw new ArgumentOutOfRangeException("The specified index is not within the acceptable range.");

      pItems.RemoveAt(index);
      pDirty = true;
    }

    public void CopyTo(Array array, int index)
    {
      pItems.CopyTo(array, index);
    }
  }
}

Remarks

The ISessionStateItemCollection interface defines the collection of session items exposed to application code by the HttpSessionStateContainer class.

The ASP.NET implementation of the ISessionStateItemCollection interface is the SessionStateItemCollection class.

If you create a class derived from the SessionStateStoreProviderBase class to store session data, you can either use the SessionStateItemCollection class to manage the stored objects or implement the ISessionStateItemCollection interface on your own collection manager.

If you implement the ISessionStateItemCollection interface, you must also create a class that inherits the SessionStateStoreProviderBase class in order to make use of your ISessionStateItemCollection implementation to manage session variables.

An ISessionStateItemCollection implementation must also implement the members of the ICollection interface.

Properties

Count

Gets the number of elements contained in the ICollection.

(Inherited from ICollection)
Dirty

Gets or sets a value indicating whether the collection has been marked as changed.

IsSynchronized

Gets a value indicating whether access to the ICollection is synchronized (thread safe).

(Inherited from ICollection)
Item[Int32]

Gets or sets a value in the collection by numerical index.

Item[String]

Gets or sets a value in the collection by name.

Keys

Gets a collection of the variable names for all values stored in the collection.

SyncRoot

Gets an object that can be used to synchronize access to the ICollection.

(Inherited from ICollection)

Methods

Clear()

Removes all values and keys from the session-state collection.

CopyTo(Array, Int32)

Copies the elements of the ICollection to an Array, starting at a particular Array index.

(Inherited from ICollection)
GetEnumerator()

Returns an enumerator that iterates through a collection.

(Inherited from IEnumerable)
Remove(String)

Deletes an item from the collection.

RemoveAt(Int32)

Deletes an item at a specified index from the collection.

Extension Methods

Cast<TResult>(IEnumerable)

Casts the elements of an IEnumerable to the specified type.

OfType<TResult>(IEnumerable)

Filters the elements of an IEnumerable based on a specified type.

AsParallel(IEnumerable)

Enables parallelization of a query.

AsQueryable(IEnumerable)

Converts an IEnumerable to an IQueryable.

Applies to

Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

See also