to maintain a web site hit counter we can keep that variable in application[‘hitcounter’] and save it using appliaction_end event to database if application reset and reload it in application_start event from database and then update it whenever it website get hit from a user. my question is what if ‘IIS’ crash then using which event i save the current value of ‘hitcounter’ to database?
to maintain a web site hit counter we can keep that variable in application[‘hitcounter’]
Share
You can’t guarantee the application works well enough to do anything during a crash. As an extreme scenario, imagine the server crashes as a result of the power cord being pulled, that the last byte of hard drive space has been used up, etc.
You can save your hitcounter to the database more often. If you don’t want to incur a database hit too often (say on every request), you can save it to the database every 10, 100 or 1000 hits, just by putting the save routine on BeginRequest event handler and save only when the number is divisible by 10, or 100.