title: How do I reference Session.Contents form a class?
body: <p>This is an ASP.NET 2010 web app written in vb. I use several Session variables. I want to pass them all to a central class and let the class manage them. However, I am having some trouble. </p>
  
  <p>Here is the code on the calling page:</p>
  
  <pre><code>Dim arrGoodSessions() As String ={"nameofsession1", "nameofsession2", "nameofsession3"}
  Utilities.ManageSessionVariables(arrGoodSessions)
  </code></pre>
  
  <p>It calls that static Utilties class. I have set a reference to System.Web. Here is the code in the class:</p>
  
  <pre><code>Imports System.Web
  Imports System.Web.SessionState
  Imports System.Web.SessionState.HttpSessionState
  Imports System.Web.HttpContext
  
  
  Public Class Utilities : Implements IRequiresSessionState
      Public Shared Sub ManageSessionVariables(ByVal arrGoodSessions As String())
          Dim alItemsToBeRemoved As New ArrayList
  
          For Each Item In Session.Contents
              If arrGoodSessions.Contains(Item.ToString) = False Then
                  alItemsToBeRemoved.Add(Item.ToString)
              End If
          Next
          For Each i As String In alItemsToBeRemoved
              Session.Contents.Remove(i)
          Next
      End Sub
  End Class
  </code></pre>
  
  <p>This attempts to simply read in some names of session variables and then cycle through all session variables and remove any I didn't list. This works when all of the cod eis on the page. But when I move this to the class, it doesn't recgonize Session.Contents.</p>