Using Application variables with global.asa....

Results 1 to 3 of 3

Thread: Using Application variables with global.asa....

  1. #1
    Zach Jones Guest

    Default Using Application variables with global.asa....

    Hi, <BR>When writing global.asa files, I have several variables created within the Sub Application_OnStart, which loads when the server starts up. Now, is there a such thing as an Sub Application_OnEnd? I have several different statistics kept using Application variables that are lost during server restarts. I was wondering if I could put some code within Sub Application_OnEnd that would write the current variable values to a file, then have them retrieved when the server restarts(Application_OnStart). Any help or insight as to whether this works or how to do this is greatly appreciated.

  2. #2
    jason Guest

    Default RE: Using Application variables with global.asa...

    yes there is an application_onend event, but be warned - it won&#039t be fired if the server crashes, only if it &#039dies of natural causes&#039<BR><BR>just use it as you would call application_onstart - i suggest persisting to XML or textfiles as the fastest option for storage here. this in fact may be a good way of setting you onstart vars - you could even write an admin interface for it...<BR><BR>jason<BR><BR>jason

  3. #3
    Join Date
    Dec 1969

    Default RE: Using Application variables with global.asa...

    As Jason correctly points out, Application_onEnd won&#039t be called on *any* kind of abnormal termination of IIS (including power failures, as well as crashes).<BR><BR>For this reason, I *never* rely on Application_onEnd to do *anything*.<BR><BR>Depending upon how critical the info is that you are keeping--and upating--in those Application values, you might want to write the new values to a file or database any time they are changed (not good if that is once per user page hit!), any time a new session starts or ends, or maybe just periodically. <BR><BR>How do you do the last choice? Just put code in Session_onStart and Session_onEnd to check if more than xxx period of time has elapsed since the last update and, if so, write out the new values. And, if you take this route, you use the same code in Application_onEnd, of course, just for the odd time when somebody actually shuts down IIS gracefully.<BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts