DEV4 Blog

  • Home
  • /
  • Blog
  • /
  • Handle Session Variables Without Using Magic Strings
Public Class Sessions

    Private Sub New()

        blnPriceListActive = false

    End Sub


    Public Shared ReadOnly Property Current As Sessions

    Get

        Dim sesSession As Sessions = CType(HttpContext.Current.Session("__MySession__"), Sessions)

        If sesSession Is Nothing Then

        sesSession = New Sessions()
        HttpContext.Current.Session("__MySession__") = sesSession
    
        End If
   
        Return sesSession


    End Get

    End Property


    Public Property blnPriceListActive As Boolean
        Public Property strUserName as String
        Public Property strUserEmail As String
        Public Property lngUserID As Long
        Public Property strSelectedLanguage as String
        Public Property Locations As List(Of Location)

End Class

Usage:

Sessions.Current.lngUserID= 7



Published on 25 Feb 2019

Add new comment...