Hi,
Refer the below code.
Logout clicked.
Protected Sub LogoutButton_Click(sender As Object, e As EventArgs)
Session("LogOutClicked") = True
Session.Abandon()
Response.Redirect("~/Home.aspx")
End Sub
Global.asax
Private Sub Session_End(sender As Object, e As EventArgs)
' Code that runs when a session ends.
' Note: The Session_End event is raised only when the sessionstate mode
' is set to InProc in the Web.config file. If session mode is set to StateServer
' or SQLServer, the event is not raised.
' Based on your session value if its not null
If Session("EmailAddress") IsNot Nothing Then
Dim emailAddress As String = Session("EmailAddress").ToString()
Dim con As New SqlConnection(ConfigurationManager.ConnectionStrings(1).ConnectionString)
Dim cmd As New SqlCommand()
cmd.CommandType = CommandType.Text
If Session("LogOutClicked").ToString().ToLower() = "true" Then
cmd.CommandText = (Convert.ToString("UPDATE RegisteredCustomers SET LogoutDate = '" + DateTime.Now.ToShortDateString() + "' , LogoutTime ='" + DateTime.Now.ToLongTimeString() + "' WHERE EmailAddress ='") & emailAddress) + "'"
Else
Dim timeSpan As System.TimeSpan = New TimeSpan(0, Session.Timeout, 0)
cmd.CommandText = (Convert.ToString("UPDATE RegisteredCustomers SET LogoutDate = '" + DateTime.Now.ToShortDateString() + "' , LogoutTime ='" + DateTime.Now.Subtract(timeSpan) + "' WHERE EmailAddress ='") & emailAddress) + "'"
End If
con.Open()
cmd.Connection = con
cmd.ExecuteNonQuery()
con.Close()
SendHTMLMail()
End If
Session.Abandon()
Session.Clear()
Session.RemoveAll()
End Sub