|
Well, I don't know a good place to send you so I'll attempt to describe what I do. You can put anything into the session, to keep it managable I use an object, then when I come across something else that needs to be in there I modify the class.
Lately I have been using the term SessionBag for my class name, it's a virtual bag holding all the stuff I need on all my sites pages. Here is a very simple example of a SessionBag class.
-----
Public Class SessionBag
Private m_User As User
Private m_Connectionstring as string
Public Sub New(Byval Connectionstring as string)
m_Connectionstring = Connectionstring
End Sub
Public ReadOnly Property Connectionstring()
Get
Return m_Connectionstring
End Get
End Property
Public Property User as User()
Get
Return m_User
End Get
Set(ByVal Value As User)
m_User = Value
End Set
End Property
End Class
-----
Then in my Global.asax file, in the session_start event I dim a new SessionBag object and put it into the session
----
Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
Dim SB As New SessionBag("mydbconnectionstringgoeshere")
session.item("SessionBag") = SB
End Sub
----
Then on each of my web forms I add a readonly property called SessionBag that references the sessionbag object I have in the session.
----
Private readonly property SessionBag as SessionBag
Get
Return Session.Item("SessionBag")
End Get
End Property
----
Now each page can get to your neatly organized session object simply by calling it's sessionbag property.
Ex: On the login page you would verify the username and password, if correct you would load the user object and throw it into the sessionbag instance simply by saying...
if usernamepasswordcorrect then
dim usr as new User
usr.Load("Keith")
SessionBag.User = usr
end if
This might not seem like a big advantage but when you have a lot of things to manage while a user is logged into your app this makes it much easier to keep track of everything.
Probably the biggest advantage for me is that I write most of my business objects to simply take 1 argument to the constructor, that argument is a SessionBag.
If you want more info/clarification/examples on this let me know.
Keith
|