Adding session timeout on ASP.NET is straightforward and there are may ways to implement it. Today, I will discuss two (2) ways to do it:
1. Add sessionState entry on the web.config file

Or you can do the same thing using IIS Manager > Default Web Site > Properties > ASP.NET > EDIT Configuration.


Session Timeout Event on Global.asax
When user session times out it calls Session_End event and then when the user referesh the page again, it will create a new session and the Session_Start event is fired.
2. More control using Session objects
If you need more control on the session objects, you can create your own ID like the one below
Dim sessionid As Guid = Guid.NewGuid()
Session(sessionid) = sessionid.ToString
You can put this on you source page before redirecting to the page you want to monitor for timeouts. Example you can put in on a menu button as shown below:
Private Sub bntLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bntPage1.Click
Response.Redirect("home.aspx")
End Sub
Then on your destination page, put the following code on Page_Init event.
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
InitializeComponent()
CheckSessionTimeout()
End Sub
Private Sub CheckSessionTimeout()
If Session("sessionid") Is Nothing Then
Response.Redirect("login.aspx")
End If
End Sub
Continue Reading...