Generic ASP.NET Session Wrapper





4
Date Submitted Thu. Nov. 2nd, 2006 7:50 AM
Revision 1 of 1
Beginner fracturedpsyche
Tags "ASP.NET" | "generics" | "session"
Comments 0 comments
This class uses generics and provides functions that wrap writing to and reading from an ASP.NET session.

    Public Class SessionHelper(Of T)

#Region "External Methods"
        Public Shared Function ReadSessionItem(ByVal name As String) As T
            Dim value As T = Nothing

            value = CType(System.Web.HttpContext.Current.Session(name), T)

            Return value
        End Function

        Public Shared Sub WriteSessionItem(ByVal name As String, ByVal value As T)
            Dim item As Object = System.Web.HttpContext.Current.Session(name)

            If item Is Nothing Then
                System.Web.HttpContext.Current.Session.Add(name, value)
            Else
                System.Web.HttpContext.Current.Session(name) = value
            End If
        End Sub
#End Region

    End Class
 

Tim Ehrhart

Comments

There are currently no comments for this snippet.

Voting