Sessions never end (again) - Please help

Discussion in 'ASP .Net' started by D. Shane Fowlkes, Jun 25, 2004.

  1. This is a repost (pasted below). Since my original post, I've double
    checked the system clock and set all IIS Session Timeout values to 10
    minutes. Still ...the problem occurs. I've also installed Deep Metrix Live
    Stats 6.2 XPS just to make sure nothing really strange was going on was
    going on. Still....the sessions only increment...or should I say my counter
    in my asax file.... and never goes down.

    If it matters, this machine is hosting 3 sites and it has a single IP
    address. I've set IIS 5 to look at the host headers and redirect to the
    "site" on itself. This is done every day and I can't possibly see how this
    would effect the Sessions but you never know.

    I'm totally stumped!! Thoughts?....


    *****************

    I'm using ASP(.NET) trickery to show the number of "current users" on one of
    my web sites (http://www.drpt.virginia.gov). I use this method on a few of
    my sites but it seems that only this one (on this machine) gives me trouble.
    The trouble seems that the sessions simply never end so the code in my Sub
    Session_OnEnd is never fired. As I understand it, sessions will expire
    after 20 minutes but default if there is no further activity from the
    requestor. Yet, my counter never seems to decrement....only increment. My
    code is below and I don't think it's a code (ASP) issue...this is a common
    trick and this exact code works fine on other sites. I think it's an issue
    with this one machine. Can anyone help or tell me what to check??

    Thanks!!

    My global.asax file:

    '***************************************************

    Sub Application_OnStart

    Application("URLSeed") = "http://www.drpt.virginia.gov/"
    Application("CurrentSessions") = 0
    Application("TotalSessions") = 0

    End Sub

    '**************************************************

    Sub Application_OnEnd

    Application("URLSeed") = Nothing

    End Sub

    '**************************************************

    Sub Session_OnStart

    '============================================
    '===== Updating Current Sessions ====================
    '============================================
    Application.Lock

    Application("TotalSessions") = CInt(Application("TotalSessions")) + 1
    Application("CurrentSessions") = CInt(Application("CurrentSessions")) + 1

    Application.Unlock

    End Sub

    '**************************************************

    Sub Session_OnEnd

    Application.Lock

    Application("CurrentSessions") = CInt(Application("CurrentSessions")) - 1

    Application.Unlock

    'Killing user's session variables
    Session.Abandon()

    End Sub
    '***************************************************
     
    D. Shane Fowlkes, Jun 25, 2004
    #1
    1. Advertisements

  2. I assume you are using InProc session state mode?
     
    Paul Glavich [MVP - ASP.NET], Jun 25, 2004
    #2
    1. Advertisements

  3. D. Shane Fowlkes

    Patrice Guest

    What if you try Session_End instead ?

    Also I would start bu putting there something else to see wether or not it's
    excuted...

    Patrice


    --
     
    Patrice, Jun 25, 2004
    #3
  4. Not sure. Can you clarify a little? Thanks


    CInt(Application("CurrentSessions")) -
     
    D. Shane Fowlkes, Jun 25, 2004
    #4
  5. In your web.config, you have the setting :-
    <sessionState mode="InProc" cookieless=false etc......
     
    Paul Glavich [MVP - ASP.NET], Jun 25, 2004
    #5
  6. Thanks! I added that and did a little research on InProc. We'll see what
    happens. I've also been using Session_OnEnd in my asax file instead of
    Session_End as I showed in my code.

    So what's the difference and did this OnEnd change just to "End" in .NET?
    I've always used OnStart and OnEnd in my asa (classic) files. Yet all my
    books and online resources just mentioned "End" but never explain that this
    has changed. Did it infact change?

    Thanks again!
     
    D. Shane Fowlkes, Jun 25, 2004
    #6
  7. Your web.config will contain a line like :-

    <sessionState mode="InProc" .....>

    or some other similar setting.(StateServer etc...). If you can provide the
    contents of this entry, that may help.
     
    Paul Glavich [MVP - ASP.NET], Jun 28, 2004
    #7
  8. Thanks! My web.config file is as follows:

    <configuration>
    <system.web>
    <customErrors mode="Off" />
    <compilation debug="true" />
    <sessionState mode="InProc" />
    </system.web>
    </configuration>


    I'm STILL having this problem though. I came back this a.m. and checked it
    and the site had "2000+ current users" which of course is false. It just
    counted ALL users over the weekend and never released the sessions. I also
    believe there is some confusion on my part on Session_OnEnd and Session_End
    (see reply above).
     
    D. Shane Fowlkes, Jun 28, 2004
    #8
  9. ....and finally, I added a AdHoc counter to see if indeed sessions are ever
    ending. This will simply (in theory) increment a value in a counter table...


    global.asax file:

    <%@ Import Namespace="System.Data" %>
    <%@ Import Namespace="System.Data.SqlClient" %>
    <%@ Import Namespace="System.Web.Mail" %>

    <script language="vb" runat="server">

    '***************************************************************************
    ***********************************************
    Sub Application_OnStart

    Application("URLSeed") = "http://www.drpt.virginia.gov/"
    Application("CurrentSessions") = 0
    Application("TotalSessions") = 0

    End Sub
    '***************************************************************************
    ***********************************************



    '***************************************************************************
    ***********************************************
    Sub Application_OnEnd

    Application("URLSeed") = Nothing

    End Sub
    '***************************************************************************
    ***********************************************


    '***************************************************************************
    ***********************************************
    Sub Session_OnStart

    'Updating Current Sessions
    Application.Lock

    Application("TotalSessions") = CInt(Application("TotalSessions")) + 1
    Application("CurrentSessions") = CInt(Application("CurrentSessions")) + 1

    Application.Unlock

    End Sub
    '***************************************************************************
    ***********************************************



    '***************************************************************************
    ***********************************************
    Sub Session_End

    Application.Lock

    Application("CurrentSessions") = CInt(Application("CurrentSessions")) - 1

    Application.Unlock

    'Killing user's session variables
    Session.Abandon()

    'Call Test Sub Routine
    UpdateSessionEndTable()

    End Sub
    '***************************************************************************
    ***********************************************


    '***************************************************************************
    ***********************************************
    Sub UpdateSessionEndTable()

    Dim conSqlServer As SqlConnection
    Dim strUpdateSQL As String
    Dim cmdUpdate As SqlCommand
    Dim strConnectString As String

    strConnectString = "server=...blah...."
    strUpdateSQL = "UPDATE SessionEndCounter SET Counter = " &
    "[SessionEndCounter].[Counter] + 1 "

    conSqlServer = New SqlConnection(strConnectString)
    cmdUpdate = New SqlCommand(strUpdateSQL, conSqlServer)
    conSQLServer.Open()
    cmdUpdate.ExecuteNonQuery()
    conSQLServer.Close()

    End Sub
    '***************************************************************************
    ***********************************************

    </script>
     
    D. Shane Fowlkes, Jun 28, 2004
    #9
  10. D. Shane Fowlkes

    Patrice Guest

    Which one are you using (Session_OnEnd, Session_End ?) AFAIK under ASP.NET
    you should use Session_End.
    For now you could keep both and use an application variable to count how
    often it is fired (hopefully you'll find Session_End always fires while
    Session_OnEnd is never called).

    In some cases, the On<EventName> *method* is what the class does for you on
    this event (in particular it raises the <EventName> event) and the
    <EventName> *event* is to declare what you would like to do. That's probably
    why they renamed the event compared with ASP classic.
     
    Patrice, Jun 28, 2004
    #10
  11. Thanks...at the moment, it's Session_End (see reply below for my asax
    file).
     
    D. Shane Fowlkes, Jun 28, 2004
    #11
  12. And after running this counter for an hour, I have 30+ ended sessions so
    infact, the Session_End IS firing. The problem MUST be with my code......

    =(



     
    D. Shane Fowlkes, Jun 28, 2004
    #12
  13. NEVERMIND! The problem is so embarrassing, I won't even tell you want it
    was.

    <rolling eyes>

    It was in fact my code.
     
    D. Shane Fowlkes, Jun 28, 2004
    #13
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.