Hi Derek,
I try to keep all my user-specific stuff in my Main Form (ie, Form1... or whatever). One MainForm is created per user session. Even if the user opens up multiple browser tabs to the application - only one Main Form instance will be created for them, which is good since that user's session data will be shared across multiple browser tabs.
I try to stay away from storing data in the Session/VWGContext if I can help it. I prefer to work with strongly-typed objects instead of strings... I like compile-time checking.
So any variables/objects you store in your Main Form will only be accessible from within that user session. Be sure to declare your variables in your Main Form as Public/Friend/Private... but NOT as Shared. A Shared variable in the Main Form would give all users access to the same piece of information, and they could overwrite eachother's data, too. So be sure to not use Shared variables in the Main Form.
Here's a good example for you. Create a simple class as a container & expose your variables from it (like Palli's class... excellent example, Palli!). Something like this:
Public Class SessionVariables
Public Username As String
Public IsAdmin as Boolean
End Class
Then in your MainForm, simply put this at the top (outside of any methods):
Public mySessionVariables As New SessionVariables
Now, I'd create a Shared class as a helper class, which I always do in my projects. For Instance:
Public Class Util
Public Shared Function GetSessionVariables(ByVal myControl as Control) As SessionVariables
'Gets the MainForm belonging to the current user
Dim myForm As MainForm = CType(myControl.Context.MainForm, MainForm)
Return myForm.mySessionVariables
End Function
Private Sub New 'Prevent instantiation
End Sub
End Class
Now, from anywhere in your application - You can instantly access that user's SessionVariable object. Simply import/include Util and do this:
GetSessionVariables(Me).Username
GetSessionVariables(Me).IsAdmin
By passing Me, which is the current control you're in - you automatically pass the user Context as well. Hope this helps!
Ryan
PS. Database connection strings belong in your web.config, because they are application-wide, not user-specific. Use the ConfigurationManager to read from your web.config.