I posted earlier on this site for help on where to set a command when a user session timesout. I posted this in the global.asax file:

Imports System.Web
Imports System.Web.SessionState
Imports System.Diagnostics

Public Class Global Inherits System.Web.HttpApplication

Sub Application_Start(ByVal Sender As Object, ByVal E As EventArgs)
  Application("CurrentUsers") = 0
  Application("TotalSessions") = 0
  Application("TotalSessionsStartDate") = DateTime.Now.ToString("d")
  Application("TotalHits") = 0
  Application("TotalHitsStartDate") = DateTime.Now.ToString("d")
End Sub
Sub Application_BeginRequest(ByVal Sender As Object, ByVal E As EventArgs)
  Application("TotalHits") += 1
End Sub
Sub Session_Start(ByVal Sender As Object, ByVal E As EventArgs)
  Application("CurrentUsers") += 1
  Application("TotalSessions") += 1
End Sub
Sub Session_End(ByVal Sender As Object, ByVal E As EventArgs)
  Application("CurrentUsers") -= 1
  Dim conLogout As New OdbcConnection( System.Configuration.ConfigurationManager.AppSettings.Get("ConnectionString") )
  Dim cmdUpdate2 As New OdbcCommand( "UPDATE ProfileComments SET WasRead=1 WHERE ReceiveUserID=" & Session("UAID") & " AND WasRead=0", conLogout )
  Dim cmdUpdate3 As New OdbcCommand( "UPDATE Messages SET WasRead=1 WHERE ReceiveUserID=" & Session("UAID") & " AND WasRead=0", conLogout )
End Sub
Sub Application_End(ByVal Sender As Object, ByVal E As EventArgs)
	Application("CurrentUsers") = Nothing
End Sub

End Class

Two things:
1. It has never.. ever done the commands it was supposed to. Even when waiting for 2-3 days for a session to timeout, where the timeout is at 20 minutes on the web.config file.
2. I cannot seem to combine all three queries into one. Any ideas on that part? or even condense into two?

I am looking for a way to make a user appear offline when they timeout or logout or close the browser (which deals with timeout). Any help?

9 Years
Discussion Span
Last Post by jaredclinton

Can anyoen help? I need to figure out a way to "logoff" a user.

Is there a way to check every session on the server?


Dear SheSaid,
What mode of SessionState do you use ?
In my application, I use SQLServer mode and the session is never expired. When using InProc, it works.

To trigger Session_End you need call Session.Abandon()

Im my project, to trigger Session_End, I use 2 events. 1. When users Click Log Off button and 2. When users Close Internet Explorer by clicking X or using File->Close.

For number 2, I use JavaScript to Check if users close the IE, after that I call Webservice to trigger Session.Abandon()

 <WebMethod(EnableSession:=True)> Public Sub ClearSession(ByVal SessionID As String)
End Sub

function IEClose()
       if (event.clientY < 0) 
            objXML = new ActiveXObject("Microsoft.XMLDOM");
            objXML.async = false;
            var sSession;
            sSession = "<%= Session("SessionID") %>";
            strSql = "BMIWebService.asmx/ClearSession?SessionID=" + sSession;
            return true;            

<frameset rows="8%,*" framespacing="0" frameborder="0" border="0"  onunload="IEClose()">  
    <frame name="frmMenu" id="frmMenu" src="EOMenu.aspx" scrolling="no" />      
    <frame name="MyFrame" id="MyFrame" src="Transactions/SpecialCharges/BrowseSpecialChargesTRF.aspx"/>

Edited by mike_2000_17: Fixed formatting


Yeah I know of the work around for IE, but a lot of the users on this site work with mozilla as well. I was hoping for a more global action instead of a bunch of small work arounds. Is there anything that works for Mozilla as well?

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.