I have an MVC 2 app that has a System.Timers.Timer object starting up during Application_Start in global.asax. One of the things this timer needs to do is generate a daily e-mail to users when they have an item to review in their work queue. Inside the e-mail is a link back to the item to review.
In code I have running in various controller actions, I use code like this to generate URLs that can be e-mailed to users:
UriBuilder builder = new UriBuilder(Request.Url);
builder.Path = Url.RouteUrl("ReviewDetails", new { id = reviewId });
return builder.ToString();
I would like to do the same inside my Timer's elapsed method in global.asax, but there is no HttpContext at that point, so I'm not able to programatically determine the URL.
I think the only solution is to store the site's root (ex: http://intranet.domain.com/MyApp) in the web.config and then use that to build the URL, like this:
string url = string.Concat(ConfigurationManager.AppSettings["SiteRoot"], "/Review/", reviewId.ToString());
I'm putting this out in the cloud to see if there are any better solutions to programatically genererating a URL for the client when the HttpContext is not available.