Link to home
Start Free TrialLog in
Avatar of REA_ANDREW
REA_ANDREWFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Global.asax file

Hi,

I am starting to use the global.asax file, as I have never touched on it before. I successfuly increment an application value when a session starts, but when a session ends, I subtract one from this value. The Session End process is not firing, and the value just keeps increasing. Please could some one advise.

Thanks in advance

Andrew

P.s. My Code

<%@ Application Language="C#" %>

<script runat="server">

   
    void Application_Start(object sender, EventArgs e)
    {
        Application["NoUsers"] = 0;
        // Code that runs on application startup

    }
   
    void Application_End(object sender, EventArgs e)
    {
        //  Code that runs on application shutdown
        Application["NoUsers"] = Convert.ToInt32(Application["NoUsers"]) - 1;
    }
       
    void Application_Error(object sender, EventArgs e)
    {
        // Code that runs when an unhandled error occurs
        Application["NoUsers"] = Convert.ToInt32(Application["NoUsers"]) - 1;
    }

    void Session_Start(object sender, EventArgs e)
    {
        Application["NoUsers"] = Convert.ToInt32(Application["NoUsers"])+1;
        Response.Write(Application["NoUsers"].ToString());
        // Code that runs when a new session is started

    }

    void Session_End(object sender, EventArgs e)
    {
        Application["NoUsers"] = Convert.ToInt32(Application["NoUsers"]) - 1;
        // Code that runs when a session ends.
        // Note: The Session_End event is raised only when the sessionstate mode
        // is set to InProc in the Web.config file. If session mode is set to StateServer
        // or SQLServer, the event is not raised.

    }
       
</script>
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

Are you actually waiting long enough for the sessions to expire when testing ?
Avatar of REA_ANDREW

ASKER

Does the session automatically end when a browser window is shut?
ASKER CERTIFIED SOLUTION
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Right, thanks for that, much appreciated