How can I request local pages in the background of an ASP.NET MVC app?
- by flipdoubt
My ASP.NET MVC app needs to run a set of tasks at startup and in the background at a regular interval. I have implemented each task as a controller action and listed the app-relative path to the action in the database. I implemented a TaskRunner process that gets the urls from the database and requests each one at a regular interval using WebRequest.Create, but this throws a UriFormatException. I cannot use this answer or any code that plucks values from HttpContext.Current.Request without getting an HttpException with the message "Request is not available in this context". The Request object is not available because my code uses System.Threading.Timer to do background processing, as recommended here. Here are my questions:
Is there really no way to make local web requests within an ASP.NET web app?
Is there really no way to dynamically ascertain the root path to the web app even using static dependencies in ASP.NET?
I was trying to avoid storing the app's root path in the database (as FogBugz does with its "Maintenance Path"), but is this best option?