How can I request local pages in the background of an ASP.NET MVC app?

Posted by flipdoubt on Stack Overflow See other posts from Stack Overflow or by flipdoubt
Published on 2010-05-27T14:13:57Z Indexed on 2010/05/27 14:31 UTC
Read the original article Hit count: 224

Filed under:

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:

  1. Is there really no way to make local web requests within an ASP.NET web app?
  2. Is there really no way to dynamically ascertain the root path to the web app even using static dependencies in ASP.NET?
  3. 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?

© Stack Overflow or respective owner

Related posts about asp.net-mvc