Using Session Events

Just as applications have events, the session has related events also: session_OnStart and session_OnEnd. Figures 5.5, 5.6, and 5.7 demonstrate how to implement session and application events within your Global.asax files.

Figure 5.5 Session Events in Global.asax

<script runat=server>

Sub Session_onStart(ByVal sender As Object, ByVal e As EventArgs)

'# lock the application to prevent clashes Application.Lock()

'# increment application counter Application("cntApplication") += 1

'# unlock application Application.UnLock()

End Sub

Figure 5.6 Using Session Events

Continued

Figure 5.6 Continued

<body bgcolor="white">

'# lock the application to prevent clashes Application.Lock()

'# increment application counter Application(page.ToString) += 1

'# unlock application Application.UnLock()

'# increment session counter Session(page.ToString) += 1

The application has been visited <b><%=application("cntApplication")%></b>

times since the application started<br>

This page has been visited <b><%=application(page.toString)%></b> times since the application started<br>

You have visited this page <b><%=session(page.toString)%></b> times in this session<br>

Figure 5.7 Application Variable Updated Using Session Events

0 0

Post a comment