Hey guys, I’m trying to create a web app similar to a web crawler on my site. I have just about all the code done to do the crawling, but I still need to physically go to the web page to activate the code. Is there any way I could have my ASP.NET code execute automatically once every day on the server? (I’m using godaddy if that makes any difference)
Thank you
You don’t want a “page,” you want a scheduled console app or a Windows service. A page, by design, is a request-able server resource. (Look into RESTful design.) It’s meant to be invoked by a request from a client, perhaps perform some server-side logic, and return a response to that client. End of story.
Your site could spawn off a thread of some sort on the start of the application, I suppose. Seems like a bit of a hack to me, though. But if that’s the only option you have with your hosting provider then that may indeed be the way to go. (Though you’d still have to call the page at least once to start it.) But, ideally, you’d want an on-going process to be handled by an application or Windows service outside of the site itself.
(If you do go with a thread that’s spawned at application startup, just be aware of the various things that can cause an application to re-start. Once it’s up, that doesn’t mean it’s going to stay up. Any change to the config file, changes to pages or code in certain project types, IIS wants to free up resources and feels like restarting the pool, etc.)