Click here to Skip to main content
15,891,943 members
Please Sign up or sign in to vote.
4.67/5 (3 votes)
See more:
I need to run a small function that gets called 'on startup' for a web application, to check if the web server's system time is the same as the DB server, and log an error if not. The web server is supposed to sync on a time server, but I want to detect if this doesn't occur.

Is Application_Start the right place for this? If not, where should I do it?
Posted
Comments
Pravin Patil, Mumbai 11-Mar-11 2:45am    
Try http://www.techrepublic.com/article/working-with-the-aspnet-globalasax-file/5771721
You will find every method in Global.asax.

Hope this helps.
All the best.

Yes, Application_Start (in Global.asax) is the place for it. But note that the web server shuts down the application when there are no requests for a specified period of time.
The application will be restarted (& Application_Start called) again on the next request.
So don't be surprised if your code in Application_Start is called often.
 
Share this answer
 
Comments
Manfred Rudolf Bihy 11-Mar-11 3:38am    
The value controlling that interval can be configured so you do have some control over how often this event will occur. 5+
Brady Kelly 11-Mar-11 3:44am    
@Manfred R. Bihy, How would I go about configuring that?
Brady Kelly 11-Mar-11 3:53am    
@strogg That sounds right then. I was worried that _Start would not be called often enough, but even once a day is probably good.
I think the default timeout is 20 minutes in IIS 7
You can alter it by going to the Connections pane ->Application Pools ->Advanced settings (for the pool which hosts your app)-> Idle Timeout

You can even disable it & it'll never be shutdown.

But it's a bad idea for you to meddle them just for the problem you have.

I suggest you keep the previous run time in a simple file in App_Data & check it to see if at least 24 hrs is passed (on Application_Start)

--Edited--
PS: You also don't get to access these things on many shared hosting providers :)
 
Share this answer
 
v2
Comments
Brady Kelly 11-Mar-11 5:41am    
Yes, I'm leaning towards checking the last run time in a frequently called, guaranteed application event.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900