The code below should help you..
--
Regards
John Timney
ASP.NET MVP
Microsoft Regional Director
---somepage.aspx -----
<html>
<script language="VB" runat="server">
Sub Page_Load(Src as object, E as EventArgs)
MyGlobals.UserCount +=1
Response.Write(MyGlobals.UserCount.ToString())
End Sub
</script>
<body style="font: 10pt verdana">
Timneys Test
<form runat="server">
</form>
</body>
</html>
---global.asax----------
<%@ Application Classname="MyGlobals" %>
<script language="VB" runat="server">
public shared UserCount as integer = 1
Sub Application_OnStart()
' Application startup code goes here.
End Sub
Sub Session_OnStart()
' Session startup code goes here.
Application.Lock()
Application("SomeGlobalCounter") =
CType(Application("SomeGlobalCounter"),Integer) + 1
Application.UnLock()
End Sub
Sub Session_OnEnd()
' Session cleanup code goes here.
End Sub
Sub Application_OnEnd()
' Application cleanup code goes here.
End Sub
</script>
"Goober" <> wrote in message
news:ubI%...
> I converted a website that was done in ASP to dotnet, and brought over a
> number of items, some of which don't appear to work in the same way on
> dotnet as they did on ASP.
>
> One of them is an application variable.
>
> I have this code in my global.asax in the Sub Session_Start:
>
> Application.Lock() 'Add 1 to active visitor count when new visitor
> Application("counter99") = Application("counter99") + 1
> Application.UnLock()
>
> It's a counter that I increment each time a user logged in to my old ASP
> site.
>
> I have this in the Sub Session_OnEnd to decrement the same counter:
>
> Sub Session_OnEnd(ByVal sender As Object, ByVal e As EventArgs)
> Application.Lock() 'Sub 1 active visitor count when new visitor
> Application("counter99") = Application("counter99") - 1
> Application.UnLock()
> End Sub
>
> I know that in ASP, you couldn't really rely on the session end to get a
> "good" accurate count on users, but in ASP, it generally worked, and
> gave you a reasonable estimate of how many users were hitting the site
> at a time.
>
> In dotnet, this counter registers a number exponentially higher than
> what it did in ASP.
>
> Is there a way I can implement a counter for current users of the
> website that would be a tad more accurate than this?
>
> Any help appreciated.
>
> Thanks
>
> BC
|