how to test application_onend on local server

akohl's picture

They have: 117 posts

Joined: Feb 2001

I have created a hit counter which writes the number of hits to each page to a database file when the application ends. How to I get this event to take place so that I can test the counter? Right clicking on the default website in the internet service manager doesn't do it.
Reducing session timeout to the site to 1 minute also does not seem to work.

Here is the script which is placed into the application_onEnd subroutine in the global asa file. I haven't been able to test the "else" instance where the website looses last vister for the second time and the hits for each page get added. The application onEnd event just doesn't seem to happen again.

For Each Key in Application.Contents
rs1.find "page_name='"&Key&"'"
if rs1.eof then
rs1.addnew
rs1.fields("page_name")=Key
rs1.fields("total_hits")=Application(Key)
rs1.fields("last_hit_entry")= now()
rs1.update
else
rs1.fields("total_hits")=cint(rs1.fields("total_hits"))+Application(Key)
rs1.fields("last_hit_entry")= now()
rs1.update
end if
rs1.movefirst

Next 
'

Andy Kohlenberg
Jerusalem, Israel

Peter J. Boettcher's picture

They have: 812 posts

Joined: Feb 2000

First off, putting any type of function in the Application_OnEnd isn't a good idea. Application_OnEnd is VERY unpredictable, sometimes it fires, sometimes it doesn't. My first piece of advice, don't use it.

Try moving that piece of code into the Session_OnEnd. Then to test it just create a page and include "Session.Abandon" and Session_OnEnd should fire.

PJ | Are we there yet?
pjboettcher.com

akohl's picture

They have: 117 posts

Joined: Feb 2001

thanks. I'll take your advice on that. If it doesn't always fire, then I wouldn't want to use it to record data that will be lost if it doesn't.

Just out of curiosity. When is it supposed to fire? Right away, when when the last browser leaves the site or some period of time after that?

Andy Kohlenberg
Jerusalem, Israel

Peter J. Boettcher's picture

They have: 812 posts

Joined: Feb 2000

From my experience, the Application_OnEnd fires (when it works) when IIS is either stopped or shut down.

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.