Solved

Global.asax file

Posted on 2006-07-10
4
907 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
  • 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
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…

830 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