The WebSessionContext class allows you to specify which session the Session object should point to for code that does not have access to a session, such server-driven classes (such as sockets or threads) or the WebApplication class.
identifier As String
source As WebSession
Session As WebSession
The session the WebSessionContext refers to.
This property is read-only.
Constructor(identifier As String)
Creates a WebSessionContext from the WebSession.Identifier passed.
Constructor(source As WebSession)
Creates a new WebSessionContext from the WebSession passed.
Immediately stops the session context, rather than waiting until the WebSessionContext has been disposed of.
The constructor parameter is required.
Inside user-driven events or threads created inside user-driven events, such as a Button push, the Session object is automatically available. However, in server-driven events, such as a Socket DataAvailable event, there is no way for the framework to know which session to communicate with. Should you need to communicate with a session from one of these events, this class can be used to inform the framework to which session the Session object should point.
The session context automatically stops when the object goes out of scope.
Creating a WebSessionContext within a session will raise an UnsupportedOperationException.
When placed in the WebApplication.UnhandledException event, this example will change the current page to another page from the application (called ExceptionPage in this case) to inform each user that the application is about to crash due to an unhandled exception.
' Iterate through all sessions and have them display a new
For Each activeSession As WebSession In App.Sessions
' Without creating a WebSessionContext here, creating
' the page would fail triggering a SessionNotAvailableException.
Var context As New WebSessionContext(activeSession)
' Because we have a context, we can create a new
' ExceptionPage and assign it to the session.
context.Session.CurrentPage = New ExceptionPage
Web projects on all supported operating systems.