Hi All,
I have the following code but for some reason I cannot get the Session_OnEnd
event to fire.
I am trying to limit the amount of connections a browser session can have.
Where the application is a virtual directory.
Any ideas?
------------
default.aspx.vb
Public Class WebForm1
Inherits System.Web.UI.Page
Protected WithEvents lblSessionCount As System.Web.UI.WebControls.Label
Protected WithEvents lblTotalCount As System.Web.UI.WebControls.Label
Protected WithEvents lblMSG As System.Web.UI.WebControls.Label
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not IsPostBack Then
Dim SessionCount As Integer
Dim SessionID As Integer
SessionCount = Utility.GetSessionCount(Server.MapPath("/GDAM"),
Session.SessionID)
lblSessionCount.Text = SessionCount
Dim TotalCount As Integer
TotalCount = Utility.GetTotalCount(Server.MapPath("/GDAM"))
lblTotalCount.Text = TotalCount
If SessionCount < 2 Then
If TotalCount < 6 Then
Utility.IncrementSessionCount(Server.MapPath("/GDAM"),
Session.SessionID)
GetGDAM()
Else
lblMSG.Text = "Sorry all the connections are currently
busy: " & TotalCount
End If
Else
lblMSG.Text = "Sorry too many connections for this session:
" & SessionCount
End If
End If
End Sub
Sub GetGDAM()
lblMSG.Text = "Went to get GDAM"
Session.Abandon()
End Sub
End Class
------------
sessions.xml
<SESSIONS>
<SESSION>
<ID>1</ID>
<COUNT>2</COUNT>
</SESSION>
<SESSION>
<ID>2</ID>
<COUNT>0</COUNT>
</SESSION>
</SESSIONS>
-----
Global.asax
Public Class Global
Inherits System.Web.HttpApplication
#Region " Component Designer Generated Code "
Public Sub New()
MyBase.New()
'This call is required by the Component Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Required by the Component Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Component Designer
'It can be modified using the Component Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
components = New System.ComponentModel.Container()
End Sub
#End Region
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
' Fires when the application is started
Application("Start") = Now()
End Sub
Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
' Fires when the session is started
Session.Timeout = 5
Session("Start") = Now()
Utility.NewSession(Server.MapPath("/GDAM"), Session.SessionID)
End Sub
Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
' Fires at the beginning of each request
End Sub
Sub Application_AuthenticateRequest(ByVal sender As Object, ByVal e As
EventArgs)
' Fires upon attempting to authenticate the use
End Sub
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
' Fires when an error occurs
End Sub
Sub Session_End(ByVal sender As Object, ByVal e As EventArgs)
' Fires when the session ends
Utility.KillSession(Server.MapPath("/GDAM"), Session.SessionID)
End Sub
Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)
' Fires when the application ends
End Sub
End Class
-------------
Utility.vb
Public Class Utility
Public Shared Function GetSessionCount(ByVal AppPath As String, ByVal
SessionID As String) As Integer
'''''Get Session XML'''''
Dim xmlSessions As System.Xml.XmlDocument = New
System.Xml.XmlDocument()
xmlSessions.Load(AppPath & "\sessions.xml")
Dim lstSessions As System.Xml.XmlNodeList
Dim ndSession As System.Xml.XmlNode
'''''Get the Count for this sessionid
lstSessions = xmlSessions.SelectNodes("SESSIONS/SESSION")
For Each ndSession In lstSessions
If ndSession.SelectSingleNode("ID").InnerText = SessionID Then
Return ndSession.SelectSingleNode("COUNT").InnerText
End If
Next
End Function
Public Shared Function GetTotalCount(ByVal AppPath As String) As Integer
'''''Get Session XML'''''
Dim TotalCount As Integer
TotalCount = 0
Dim xmlSessions As System.Xml.XmlDocument = New
System.Xml.XmlDocument()
xmlSessions.Load(AppPath & "\sessions.xml")
Dim lstSessions As System.Xml.XmlNodeList
Dim ndSession As System.Xml.XmlNode
'''''Total up the Session Counts
lstSessions = xmlSessions.SelectNodes("SESSIONS/SESSION")
For Each ndSession In lstSessions
TotalCount = TotalCount +
ndSession.SelectSingleNode("COUNT").InnerText
Next
Return TotalCount
End Function
Public Shared Sub IncrementSessionCount(ByVal AppPath As String, ByVal
SessionID As String)
'''''Get Session XML'''''
Dim xmlSessions As System.Xml.XmlDocument = New
System.Xml.XmlDocument()
xmlSessions.Load(AppPath & "\sessions.xml")
Dim lstSessions As System.Xml.XmlNodeList
Dim ndSession As System.Xml.XmlNode
Dim SessionCount As Integer
Dim NewSessionCount As Integer
'''''Get the Count for this sessionid
lstSessions = xmlSessions.SelectNodes("SESSIONS/SESSION")
For Each ndSession In lstSessions
If ndSession.SelectSingleNode("ID").InnerText = SessionID Then
SessionCount = ndSession.SelectSingleNode("COUNT").InnerText
NewSessionCount = SessionCount + 1
ndSession.SelectSingleNode("COUNT").InnerText =
NewSessionCount
End If
Next
xmlSessions.Save(AppPath & "\sessions.xml")
End Sub
Public Shared Sub NewSession(ByVal AppPath As String, ByVal SessionID As
String)
'''''Get Session XML'''''
Dim xmlSessions As System.Xml.XmlDocument = New
System.Xml.XmlDocument()
xmlSessions.Load(AppPath & "\sessions.xml")
'Create New Child Nodes
Dim eleSess As System.Xml.XmlElement =
xmlSessions.CreateElement("SESSION")
Dim eleID As System.Xml.XmlElement = xmlSessions.CreateElement("ID")
Dim eleCount As System.Xml.XmlElement =
xmlSessions.CreateElement("COUNT")
'Set the text
Dim eleIDText As System.Xml.XmlText =
xmlSessions.CreateTextNode(SessionID)
Dim eleCountText As System.Xml.XmlText = xmlSessions.CreateTextNode(0)
'Append parentnode to root
xmlSessions.DocumentElement.PrependChild(eleSess)
'append the nodes to the parentNode without the value
eleSess.AppendChild(eleID)
eleSess.AppendChild(eleCount)
'Save the text values to the nodes
eleID.AppendChild(eleIDText)
eleCount.AppendChild(eleCountText)
xmlSessions.Save(AppPath & "\sessions.xml")
End Sub
Public Shared Sub KillSession(ByVal AppPath As String, ByVal SessionID
As String)
'''''Get Session XML'''''
Dim xmlSessions As System.Xml.XmlDocument = New
System.Xml.XmlDocument()
xmlSessions.Load(AppPath & "\sessions.xml")
'Create New Child Nodes
Dim eleSess As System.Xml.XmlElement =
xmlSessions.CreateElement("SESSION")
Dim eleID As System.Xml.XmlElement = xmlSessions.CreateElement("ID")
Dim eleCount As System.Xml.XmlElement =
xmlSessions.CreateElement("COUNT")
'Set the text
Dim eleIDText As System.Xml.XmlText =
xmlSessions.CreateTextNode(SessionID)
Dim eleCountText As System.Xml.XmlText = xmlSessions.CreateTextNode(0)
'Append parentnode to root
xmlSessions.DocumentElement.PrependChild(eleSess)
'append the nodes to the parentNode without the value
eleSess.AppendChild(eleID)
eleSess.AppendChild(eleCount)
'Save the text values to the nodes
eleID.AppendChild(eleIDText)
eleCount.AppendChild(eleCountText)
xmlSessions.Save(AppPath & "\sessions.xml")
End Sub
End Class
------------
Any help/information is greatly appreciated.
Thank you,
Phil Lamey, EIT
CGI Consultant 3 4428
What do you expect to be causing this event?
This even is fired when the session is explicitly abandoned in code, or when
the session timeout has been reached due to no requests from the client. It
will NOT be called as soon as the user navigates away from your site or
closes the browser.
"Phil Lamey" <Ph*******@discussions.microsoft.com> wrote in message
news:36**********************************@microsof t.com... Hi All,
I have the following code but for some reason I cannot get the
Session_OnEnd event to fire.
I am trying to limit the amount of connections a browser session can have. Where the application is a virtual directory.
Any ideas? ------------ default.aspx.vb
Public Class WebForm1 Inherits System.Web.UI.Page Protected WithEvents lblSessionCount As
System.Web.UI.WebControls.Label Protected WithEvents lblTotalCount As System.Web.UI.WebControls.Label Protected WithEvents lblMSG As System.Web.UI.WebControls.Label
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer. <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init 'CODEGEN: This method call is required by the Web Form Designer 'Do not modify it using the code editor. InitializeComponent() End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here If Not IsPostBack Then Dim SessionCount As Integer Dim SessionID As Integer SessionCount =
Utility.GetSessionCount(Server.MapPath("/GDAM"), Session.SessionID) lblSessionCount.Text = SessionCount Dim TotalCount As Integer TotalCount = Utility.GetTotalCount(Server.MapPath("/GDAM")) lblTotalCount.Text = TotalCount
If SessionCount < 2 Then If TotalCount < 6 Then Utility.IncrementSessionCount(Server.MapPath("/GDAM"), Session.SessionID) GetGDAM() Else lblMSG.Text = "Sorry all the connections are currently busy: " & TotalCount End If Else lblMSG.Text = "Sorry too many connections for this
session: " & SessionCount End If End If
End Sub
Sub GetGDAM() lblMSG.Text = "Went to get GDAM" Session.Abandon() End Sub
End Class ------------ sessions.xml
<SESSIONS> <SESSION> <ID>1</ID> <COUNT>2</COUNT> </SESSION> <SESSION> <ID>2</ID> <COUNT>0</COUNT> </SESSION> </SESSIONS>
-----
Global.asax
Public Class Global Inherits System.Web.HttpApplication
#Region " Component Designer Generated Code "
Public Sub New() MyBase.New()
'This call is required by the Component Designer. InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Required by the Component Designer Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Component Designer 'It can be modified using the Component Designer. 'Do not modify it using the code editor. <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() components = New System.ComponentModel.Container() End Sub
#End Region
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs) ' Fires when the application is started Application("Start") = Now() End Sub
Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs) ' Fires when the session is started Session.Timeout = 5 Session("Start") = Now() Utility.NewSession(Server.MapPath("/GDAM"), Session.SessionID) End Sub
Sub Application_BeginRequest(ByVal sender As Object, ByVal e As
EventArgs) ' Fires at the beginning of each request End Sub
Sub Application_AuthenticateRequest(ByVal sender As Object, ByVal e As EventArgs) ' Fires upon attempting to authenticate the use End Sub
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs) ' Fires when an error occurs End Sub
Sub Session_End(ByVal sender As Object, ByVal e As EventArgs) ' Fires when the session ends Utility.KillSession(Server.MapPath("/GDAM"), Session.SessionID) End Sub
Sub Application_End(ByVal sender As Object, ByVal e As EventArgs) ' Fires when the application ends End Sub
End Class
------------- Utility.vb
Public Class Utility
Public Shared Function GetSessionCount(ByVal AppPath As String, ByVal SessionID As String) As Integer '''''Get Session XML''''' Dim xmlSessions As System.Xml.XmlDocument = New System.Xml.XmlDocument() xmlSessions.Load(AppPath & "\sessions.xml") Dim lstSessions As System.Xml.XmlNodeList Dim ndSession As System.Xml.XmlNode
'''''Get the Count for this sessionid lstSessions = xmlSessions.SelectNodes("SESSIONS/SESSION") For Each ndSession In lstSessions If ndSession.SelectSingleNode("ID").InnerText = SessionID Then Return ndSession.SelectSingleNode("COUNT").InnerText End If Next End Function
Public Shared Function GetTotalCount(ByVal AppPath As String) As
Integer '''''Get Session XML''''' Dim TotalCount As Integer TotalCount = 0 Dim xmlSessions As System.Xml.XmlDocument = New System.Xml.XmlDocument() xmlSessions.Load(AppPath & "\sessions.xml") Dim lstSessions As System.Xml.XmlNodeList Dim ndSession As System.Xml.XmlNode
'''''Total up the Session Counts lstSessions = xmlSessions.SelectNodes("SESSIONS/SESSION") For Each ndSession In lstSessions TotalCount = TotalCount + ndSession.SelectSingleNode("COUNT").InnerText Next
Return TotalCount End Function
Public Shared Sub IncrementSessionCount(ByVal AppPath As String, ByVal SessionID As String) '''''Get Session XML''''' Dim xmlSessions As System.Xml.XmlDocument = New System.Xml.XmlDocument() xmlSessions.Load(AppPath & "\sessions.xml") Dim lstSessions As System.Xml.XmlNodeList Dim ndSession As System.Xml.XmlNode Dim SessionCount As Integer Dim NewSessionCount As Integer
'''''Get the Count for this sessionid lstSessions = xmlSessions.SelectNodes("SESSIONS/SESSION") For Each ndSession In lstSessions If ndSession.SelectSingleNode("ID").InnerText = SessionID Then SessionCount =
ndSession.SelectSingleNode("COUNT").InnerText NewSessionCount = SessionCount + 1 ndSession.SelectSingleNode("COUNT").InnerText = NewSessionCount End If Next xmlSessions.Save(AppPath & "\sessions.xml") End Sub
Public Shared Sub NewSession(ByVal AppPath As String, ByVal SessionID
As String) '''''Get Session XML''''' Dim xmlSessions As System.Xml.XmlDocument = New System.Xml.XmlDocument() xmlSessions.Load(AppPath & "\sessions.xml") 'Create New Child Nodes Dim eleSess As System.Xml.XmlElement = xmlSessions.CreateElement("SESSION") Dim eleID As System.Xml.XmlElement =
xmlSessions.CreateElement("ID") Dim eleCount As System.Xml.XmlElement = xmlSessions.CreateElement("COUNT")
'Set the text Dim eleIDText As System.Xml.XmlText = xmlSessions.CreateTextNode(SessionID) Dim eleCountText As System.Xml.XmlText =
xmlSessions.CreateTextNode(0) 'Append parentnode to root xmlSessions.DocumentElement.PrependChild(eleSess)
'append the nodes to the parentNode without the value eleSess.AppendChild(eleID) eleSess.AppendChild(eleCount)
'Save the text values to the nodes eleID.AppendChild(eleIDText) eleCount.AppendChild(eleCountText) xmlSessions.Save(AppPath & "\sessions.xml") End Sub
Public Shared Sub KillSession(ByVal AppPath As String, ByVal SessionID As String) '''''Get Session XML''''' Dim xmlSessions As System.Xml.XmlDocument = New System.Xml.XmlDocument() xmlSessions.Load(AppPath & "\sessions.xml") 'Create New Child Nodes Dim eleSess As System.Xml.XmlElement = xmlSessions.CreateElement("SESSION") Dim eleID As System.Xml.XmlElement =
xmlSessions.CreateElement("ID") Dim eleCount As System.Xml.XmlElement = xmlSessions.CreateElement("COUNT")
'Set the text Dim eleIDText As System.Xml.XmlText = xmlSessions.CreateTextNode(SessionID) Dim eleCountText As System.Xml.XmlText =
xmlSessions.CreateTextNode(0) 'Append parentnode to root xmlSessions.DocumentElement.PrependChild(eleSess)
'append the nodes to the parentNode without the value eleSess.AppendChild(eleID) eleSess.AppendChild(eleCount)
'Save the text values to the nodes eleID.AppendChild(eleIDText) eleCount.AppendChild(eleCountText) xmlSessions.Save(AppPath & "\sessions.xml") End Sub
End Class
------------
Any help/information is greatly appreciated.
Thank you,
Phil Lamey, EIT CGI Consultant
I have been waiting for anything to fire the OnEnd code.
Timeout/Abandon/Navigation ... but nothing seems to make the OnEnd event
fire. I have a breakpoint in my code in the OnEnd section of the Global.asax
and it is never reached.
"Marina" wrote: What do you expect to be causing this event?
This even is fired when the session is explicitly abandoned in code, or when the session timeout has been reached due to no requests from the client. It will NOT be called as soon as the user navigates away from your site or closes the browser.
"Phil Lamey" <Ph*******@discussions.microsoft.com> wrote in message news:36**********************************@microsof t.com... Hi All,
I have the following code but for some reason I cannot get the Session_OnEnd event to fire.
I am trying to limit the amount of connections a browser session can have. Where the application is a virtual directory.
Any ideas? ------------ default.aspx.vb
Public Class WebForm1 Inherits System.Web.UI.Page Protected WithEvents lblSessionCount As System.Web.UI.WebControls.Label Protected WithEvents lblTotalCount As System.Web.UI.WebControls.Label Protected WithEvents lblMSG As System.Web.UI.WebControls.Label
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer. <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init 'CODEGEN: This method call is required by the Web Form Designer 'Do not modify it using the code editor. InitializeComponent() End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here If Not IsPostBack Then Dim SessionCount As Integer Dim SessionID As Integer SessionCount = Utility.GetSessionCount(Server.MapPath("/GDAM"), Session.SessionID) lblSessionCount.Text = SessionCount Dim TotalCount As Integer TotalCount = Utility.GetTotalCount(Server.MapPath("/GDAM")) lblTotalCount.Text = TotalCount
If SessionCount < 2 Then If TotalCount < 6 Then Utility.IncrementSessionCount(Server.MapPath("/GDAM"), Session.SessionID) GetGDAM() Else lblMSG.Text = "Sorry all the connections are currently busy: " & TotalCount End If Else lblMSG.Text = "Sorry too many connections for this session: " & SessionCount End If End If
End Sub
Sub GetGDAM() lblMSG.Text = "Went to get GDAM" Session.Abandon() End Sub
End Class ------------ sessions.xml
<SESSIONS> <SESSION> <ID>1</ID> <COUNT>2</COUNT> </SESSION> <SESSION> <ID>2</ID> <COUNT>0</COUNT> </SESSION> </SESSIONS>
-----
Global.asax
Public Class Global Inherits System.Web.HttpApplication
#Region " Component Designer Generated Code "
Public Sub New() MyBase.New()
'This call is required by the Component Designer. InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Required by the Component Designer Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Component Designer 'It can be modified using the Component Designer. 'Do not modify it using the code editor. <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() components = New System.ComponentModel.Container() End Sub
#End Region
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs) ' Fires when the application is started Application("Start") = Now() End Sub
Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs) ' Fires when the session is started Session.Timeout = 5 Session("Start") = Now() Utility.NewSession(Server.MapPath("/GDAM"), Session.SessionID) End Sub
Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs) ' Fires at the beginning of each request End Sub
Sub Application_AuthenticateRequest(ByVal sender As Object, ByVal e As EventArgs) ' Fires upon attempting to authenticate the use End Sub
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs) ' Fires when an error occurs End Sub
Sub Session_End(ByVal sender As Object, ByVal e As EventArgs) ' Fires when the session ends Utility.KillSession(Server.MapPath("/GDAM"), Session.SessionID) End Sub
Sub Application_End(ByVal sender As Object, ByVal e As EventArgs) ' Fires when the application ends End Sub
End Class
------------- Utility.vb
Public Class Utility
Public Shared Function GetSessionCount(ByVal AppPath As String, ByVal SessionID As String) As Integer '''''Get Session XML''''' Dim xmlSessions As System.Xml.XmlDocument = New System.Xml.XmlDocument() xmlSessions.Load(AppPath & "\sessions.xml") Dim lstSessions As System.Xml.XmlNodeList Dim ndSession As System.Xml.XmlNode
'''''Get the Count for this sessionid lstSessions = xmlSessions.SelectNodes("SESSIONS/SESSION") For Each ndSession In lstSessions If ndSession.SelectSingleNode("ID").InnerText = SessionID Then Return ndSession.SelectSingleNode("COUNT").InnerText End If Next End Function
Public Shared Function GetTotalCount(ByVal AppPath As String) As Integer '''''Get Session XML''''' Dim TotalCount As Integer TotalCount = 0 Dim xmlSessions As System.Xml.XmlDocument = New System.Xml.XmlDocument() xmlSessions.Load(AppPath & "\sessions.xml") Dim lstSessions As System.Xml.XmlNodeList Dim ndSession As System.Xml.XmlNode
'''''Total up the Session Counts lstSessions = xmlSessions.SelectNodes("SESSIONS/SESSION") For Each ndSession In lstSessions TotalCount = TotalCount + ndSession.SelectSingleNode("COUNT").InnerText Next
Return TotalCount End Function
Public Shared Sub IncrementSessionCount(ByVal AppPath As String, ByVal SessionID As String) '''''Get Session XML''''' Dim xmlSessions As System.Xml.XmlDocument = New System.Xml.XmlDocument() xmlSessions.Load(AppPath & "\sessions.xml") Dim lstSessions As System.Xml.XmlNodeList Dim ndSession As System.Xml.XmlNode Dim SessionCount As Integer Dim NewSessionCount As Integer
'''''Get the Count for this sessionid lstSessions = xmlSessions.SelectNodes("SESSIONS/SESSION") For Each ndSession In lstSessions If ndSession.SelectSingleNode("ID").InnerText = SessionID Then SessionCount = ndSession.SelectSingleNode("COUNT").InnerText NewSessionCount = SessionCount + 1 ndSession.SelectSingleNode("COUNT").InnerText = NewSessionCount End If Next xmlSessions.Save(AppPath & "\sessions.xml") End Sub
Public Shared Sub NewSession(ByVal AppPath As String, ByVal SessionID As String) '''''Get Session XML''''' Dim xmlSessions As System.Xml.XmlDocument = New System.Xml.XmlDocument() xmlSessions.Load(AppPath & "\sessions.xml") 'Create New Child Nodes Dim eleSess As System.Xml.XmlElement = xmlSessions.CreateElement("SESSION") Dim eleID As System.Xml.XmlElement = xmlSessions.CreateElement("ID") Dim eleCount As System.Xml.XmlElement = xmlSessions.CreateElement("COUNT")
'Set the text Dim eleIDText As System.Xml.XmlText = xmlSessions.CreateTextNode(SessionID) Dim eleCountText As System.Xml.XmlText = xmlSessions.CreateTextNode(0) 'Append parentnode to root xmlSessions.DocumentElement.PrependChild(eleSess)
'append the nodes to the parentNode without the value eleSess.AppendChild(eleID) eleSess.AppendChild(eleCount)
'Save the text values to the nodes eleID.AppendChild(eleIDText) eleCount.AppendChild(eleCountText) xmlSessions.Save(AppPath & "\sessions.xml") End Sub
Public Shared Sub KillSession(ByVal AppPath As String, ByVal SessionID As String) '''''Get Session XML''''' Dim xmlSessions As System.Xml.XmlDocument = New System.Xml.XmlDocument() xmlSessions.Load(AppPath & "\sessions.xml") 'Create New Child Nodes Dim eleSess As System.Xml.XmlElement = xmlSessions.CreateElement("SESSION") Dim eleID As System.Xml.XmlElement =
xmlSessions.CreateElement("ID") Dim eleCount As System.Xml.XmlElement = xmlSessions.CreateElement("COUNT")
'Set the text Dim eleIDText As System.Xml.XmlText = xmlSessions.CreateTextNode(SessionID) Dim eleCountText As System.Xml.XmlText = xmlSessions.CreateTextNode(0) 'Append parentnode to root xmlSessions.DocumentElement.PrependChild(eleSess)
'append the nodes to the parentNode without the value eleSess.AppendChild(eleID) eleSess.AppendChild(eleCount)
'Save the text values to the nodes eleID.AppendChild(eleIDText) eleCount.AppendChild(eleCountText) xmlSessions.Save(AppPath & "\sessions.xml") End Sub
End Class
------------
Any help/information is greatly appreciated.
Thank you,
Phil Lamey, EIT CGI Consultant
Phil,
As Marina said the Session_End event is fired only if the session
times out, is explicitly abandoned in code and I would add: if you are
using the *InProc* session state mode. What session state mode do you
use? To debug the Session_End event you could set the timeout in your
web.config to say 1 minute.
"Phil Lamey" <Ph*******@discussions.microsoft.com> wrote in message news:<6D**********************************@microso ft.com>... I have been waiting for anything to fire the OnEnd code. Timeout/Abandon/Navigation ... but nothing seems to make the OnEnd event fire. I have a breakpoint in my code in the OnEnd section of the Global.asax and it is never reached.
"Marina" wrote:
What do you expect to be causing this event?
This even is fired when the session is explicitly abandoned in code, or when the session timeout has been reached due to no requests from the client. It will NOT be called as soon as the user navigates away from your site or closes the browser.
"Phil Lamey" <Ph*******@discussions.microsoft.com> wrote in message news:36**********************************@microsof t.com... Hi All,
I have the following code but for some reason I cannot get the Session_OnEnd event to fire.
I am trying to limit the amount of connections a browser session can have. Where the application is a virtual directory.
Any ideas? ------------ default.aspx.vb
Public Class WebForm1 Inherits System.Web.UI.Page Protected WithEvents lblSessionCount As System.Web.UI.WebControls.Label Protected WithEvents lblTotalCount As System.Web.UI.WebControls.Label Protected WithEvents lblMSG As System.Web.UI.WebControls.Label
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer. <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init 'CODEGEN: This method call is required by the Web Form Designer 'Do not modify it using the code editor. InitializeComponent() End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here If Not IsPostBack Then Dim SessionCount As Integer Dim SessionID As Integer SessionCount = Utility.GetSessionCount(Server.MapPath("/GDAM"), Session.SessionID) lblSessionCount.Text = SessionCount Dim TotalCount As Integer TotalCount = Utility.GetTotalCount(Server.MapPath("/GDAM")) lblTotalCount.Text = TotalCount
If SessionCount < 2 Then If TotalCount < 6 Then Utility.IncrementSessionCount(Server.MapPath("/GDAM"), Session.SessionID) GetGDAM() Else lblMSG.Text = "Sorry all the connections are currently busy: " & TotalCount End If Else lblMSG.Text = "Sorry too many connections for this session: " & SessionCount End If End If
End Sub
Sub GetGDAM() lblMSG.Text = "Went to get GDAM" Session.Abandon() End Sub
End Class ------------ sessions.xml
<SESSIONS> <SESSION> <ID>1</ID> <COUNT>2</COUNT> </SESSION> <SESSION> <ID>2</ID> <COUNT>0</COUNT> </SESSION> </SESSIONS>
-----
Global.asax
Public Class Global Inherits System.Web.HttpApplication
#Region " Component Designer Generated Code "
Public Sub New() MyBase.New()
'This call is required by the Component Designer. InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Required by the Component Designer Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Component Designer 'It can be modified using the Component Designer. 'Do not modify it using the code editor. <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() components = New System.ComponentModel.Container() End Sub
#End Region
Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs) ' Fires when the application is started Application("Start") = Now() End Sub
Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs) ' Fires when the session is started Session.Timeout = 5 Session("Start") = Now() Utility.NewSession(Server.MapPath("/GDAM"), Session.SessionID) End Sub
Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs) ' Fires at the beginning of each request End Sub
Sub Application_AuthenticateRequest(ByVal sender As Object, ByVal e As EventArgs) ' Fires upon attempting to authenticate the use End Sub
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs) ' Fires when an error occurs End Sub
Sub Session_End(ByVal sender As Object, ByVal e As EventArgs) ' Fires when the session ends Utility.KillSession(Server.MapPath("/GDAM"), Session.SessionID) End Sub
Sub Application_End(ByVal sender As Object, ByVal e As EventArgs) ' Fires when the application ends End Sub
End Class
------------- Utility.vb
Public Class Utility
Public Shared Function GetSessionCount(ByVal AppPath As String, ByVal SessionID As String) As Integer '''''Get Session XML''''' Dim xmlSessions As System.Xml.XmlDocument = New System.Xml.XmlDocument() xmlSessions.Load(AppPath & "\sessions.xml") Dim lstSessions As System.Xml.XmlNodeList Dim ndSession As System.Xml.XmlNode
'''''Get the Count for this sessionid lstSessions = xmlSessions.SelectNodes("SESSIONS/SESSION") For Each ndSession In lstSessions If ndSession.SelectSingleNode("ID").InnerText = SessionID Then Return ndSession.SelectSingleNode("COUNT").InnerText End If Next End Function
Public Shared Function GetTotalCount(ByVal AppPath As String) As Integer '''''Get Session XML''''' Dim TotalCount As Integer TotalCount = 0 Dim xmlSessions As System.Xml.XmlDocument = New System.Xml.XmlDocument() xmlSessions.Load(AppPath & "\sessions.xml") Dim lstSessions As System.Xml.XmlNodeList Dim ndSession As System.Xml.XmlNode
'''''Total up the Session Counts lstSessions = xmlSessions.SelectNodes("SESSIONS/SESSION") For Each ndSession In lstSessions TotalCount = TotalCount + ndSession.SelectSingleNode("COUNT").InnerText Next
Return TotalCount End Function
Public Shared Sub IncrementSessionCount(ByVal AppPath As String, ByVal SessionID As String) '''''Get Session XML''''' Dim xmlSessions As System.Xml.XmlDocument = New System.Xml.XmlDocument() xmlSessions.Load(AppPath & "\sessions.xml") Dim lstSessions As System.Xml.XmlNodeList Dim ndSession As System.Xml.XmlNode Dim SessionCount As Integer Dim NewSessionCount As Integer
'''''Get the Count for this sessionid lstSessions = xmlSessions.SelectNodes("SESSIONS/SESSION") For Each ndSession In lstSessions If ndSession.SelectSingleNode("ID").InnerText = SessionID Then SessionCount = ndSession.SelectSingleNode("COUNT").InnerText NewSessionCount = SessionCount + 1 ndSession.SelectSingleNode("COUNT").InnerText = NewSessionCount End If Next xmlSessions.Save(AppPath & "\sessions.xml") End Sub
Public Shared Sub NewSession(ByVal AppPath As String, ByVal SessionID As String) '''''Get Session XML''''' Dim xmlSessions As System.Xml.XmlDocument = New System.Xml.XmlDocument() xmlSessions.Load(AppPath & "\sessions.xml") 'Create New Child Nodes Dim eleSess As System.Xml.XmlElement = xmlSessions.CreateElement("SESSION") Dim eleID As System.Xml.XmlElement = xmlSessions.CreateElement("ID") Dim eleCount As System.Xml.XmlElement = xmlSessions.CreateElement("COUNT")
'Set the text Dim eleIDText As System.Xml.XmlText = xmlSessions.CreateTextNode(SessionID) Dim eleCountText As System.Xml.XmlText = xmlSessions.CreateTextNode(0) 'Append parentnode to root xmlSessions.DocumentElement.PrependChild(eleSess)
'append the nodes to the parentNode without the value eleSess.AppendChild(eleID) eleSess.AppendChild(eleCount)
'Save the text values to the nodes eleID.AppendChild(eleIDText) eleCount.AppendChild(eleCountText) xmlSessions.Save(AppPath & "\sessions.xml") End Sub
Public Shared Sub KillSession(ByVal AppPath As String, ByVal SessionID As String) '''''Get Session XML''''' Dim xmlSessions As System.Xml.XmlDocument = New System.Xml.XmlDocument() xmlSessions.Load(AppPath & "\sessions.xml") 'Create New Child Nodes Dim eleSess As System.Xml.XmlElement = xmlSessions.CreateElement("SESSION") Dim eleID As System.Xml.XmlElement = xmlSessions.CreateElement("ID") Dim eleCount As System.Xml.XmlElement = xmlSessions.CreateElement("COUNT")
'Set the text Dim eleIDText As System.Xml.XmlText = xmlSessions.CreateTextNode(SessionID) Dim eleCountText As System.Xml.XmlText = xmlSessions.CreateTextNode(0) 'Append parentnode to root xmlSessions.DocumentElement.PrependChild(eleSess)
'append the nodes to the parentNode without the value eleSess.AppendChild(eleID) eleSess.AppendChild(eleCount)
'Save the text values to the nodes eleID.AppendChild(eleIDText) eleCount.AppendChild(eleCountText) xmlSessions.Save(AppPath & "\sessions.xml") End Sub
End Class
------------
Any help/information is greatly appreciated.
Thank you,
Phil Lamey, EIT CGI Consultant This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Phil Lamey |
last post by:
Hi All,
I have the following code but for some reason I cannot get the Session_OnEnd
event to fire.
I am trying to limit the amount of connections a browser session can have.
Where the...
|
by: bloodhound |
last post by:
Hi,
Problem with global.asa not firing 100% of the time. This error crops
up several times throughout the day but if you wait a while and reload
the page (could be 5 mins or an hour) it will...
|
by: qaz |
last post by:
For some reason my global.asa file is not firing. I have it located in the
root of my website (e.g., wwwroot\mywebsite\global.asa) and I have the web
site configured as an "application" in IIS. ...
|
by: Chris Leffer |
last post by:
Hi.
Reading the docs about the Global.asax events I noticed the names used
on the help are not the same on the file. For example, the docs talk
about Session_OnEnd but on the file I found...
|
by: Andrea Williams |
last post by:
Where is the best place to put global variables. In traditional ASP I used
to put all of them into an include file and include it in every page. Will
the Global.aspx.cs do that same thing?
...
|
by: WJ |
last post by:
I am attempting to use the Global.Asax to store my user's configuration.
Here is the concept:
1. User logs on into the site using Form Authentication.
2. I capture the user Credential, verify it...
|
by: Marc |
last post by:
Hello.
Apologies if this is the wrong group. I have created a class called
"page" which i would like to add to the global.asax and then call from
any control within the website. I have currently...
|
by: furiousmojo |
last post by:
This is a strange problem. I have a project where the contents of
global.asax application_error are not firing. It is an asp.net 2.0
application using web application projects. I have another...
|
by: Victor |
last post by:
Can I get the events in GLOBAL.ASAX to fire if a classic ASP page is being accessed by
the user?
|
by: Joe |
last post by:
Hello all!
I added a Global.asax to my application. I'm using the
Application_BeginRequest event. Everything works fine in my development
enviorment but when I publish the web site the...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |