Saturday, April 15, 2006
#
Many people have problems retrieving the session object in a dll that is loaded in your front end.
Imagen you have a front end layer, with your aspx files, and you backend (BLL /DAL) written in a class library and you want to retrieve some information you have saved in your ASP.NET session.
To be honoust it's quite simple, i'll show you how I did it:
1. Create a class witch will have acces to the session object in your back-end:
Public Class SessionManager
...
End Class
2. Since we want only 1 instance of this class we make it a singleton:
Private Sub New()
End Sub
Public Shared Function getInstance() As SessionManager
If (_Instance Is Nothing) Then
_Instance = New SessionManager
End If
Return _Instance
End Function
3. Import the class that contains the session:
Imports System.Web.HttpContext
4. Create a function that will retrieve a value from the session.
(You can also create 1 method witch will return a session object but i think this is better because it improves type safety)
Public Function getSelectedLanguage() As CultureInfo
Dim strCI As String = System.Web.HttpContext.Current.Session("SelectedLanguage")
If (strCI <> "") Then
Dim tmpCI As New CultureInfo(strCI)
Return tmpCI
Else
Return Configuration.getInstance.getDefaultLanguage()
End If
End Function
As you see, it's quite simple, have fun...