Application variable question (conversion from asp to dotnet)

Discussion in 'ASP .Net' started by Goober, Feb 10, 2005.

  1. Goober

    Goober Guest

    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
     
    Goober, Feb 10, 2005
    #1
    1. Advertising

  2. 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
     
    John Timney \(ASP.NET MVP\), Feb 10, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Charles A. Lackman
    Replies:
    1
    Views:
    1,391
    smith
    Dec 8, 2004
  2. SpamProof
    Replies:
    0
    Views:
    593
    SpamProof
    Oct 21, 2003
  3. Chuck
    Replies:
    3
    Views:
    520
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
    Feb 8, 2007
  4. noel
    Replies:
    1
    Views:
    261
    Mark Rae [MVP]
    Dec 21, 2007
  5. Alfred Sehmueller
    Replies:
    0
    Views:
    268
    Alfred Sehmueller
    Feb 20, 2004
Loading...

Share This Page