Global.asax file

Posted on 2006-07-10
Last Modified: 2012-05-05

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


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;
        // 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.

Question by:REA_ANDREW
  • 2
  • 2
LVL 52

Expert Comment

by:Carl Tawn
ID: 17071634
Are you actually waiting long enough for the sessions to expire when testing ?
LVL 20

Author Comment

ID: 17071639
Does the session automatically end when a browser window is shut?
LVL 52

Accepted Solution

Carl Tawn earned 500 total points
ID: 17071652
Nope. It ends after whatever period is specified in the session timeout, by default this is 20 minutes.
LVL 20

Author Comment

ID: 17071666
Right, thanks for that, much appreciated

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity Email  a webpage 3 30
SQL best practice question 3 36
c# LinkButton OnClientClick 2 34
Not showing JavaScript in the list 5 38
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Internet Business Fax to Email Made Easy - With  eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now