Solved

Global.asax file

Posted on 2006-07-10
4
909 Views
Last Modified: 2012-05-05
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>
0
Comment
Question by:REA_ANDREW
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 52

Expert Comment

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

Author Comment

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

Accepted Solution

by:
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.
0
 
LVL 20

Author Comment

by:REA_ANDREW
ID: 17071666
Right, thanks for that, much appreciated
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.NET Textbox input validation 4 78
asp.net mvc 2 44
Connect Gridview column to Textbox in C# 2 55
Adding Rows to Grid 4 32
In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
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…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

734 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