ASP.NET MVC: How to create a usable UrlHelper instance?

Posted by Marek on Stack Overflow See other posts from Stack Overflow or by Marek
Published on 2010-03-09T21:38:26Z Indexed on 2010/03/23 23:03 UTC
Read the original article Hit count: 331

I am using quartz.net to schedule regular events within asp.net mvc application.

The scheduled job should call a service layer script that requires a UrlHelper instance (for creating Urls based on correct routes (via urlHelper.Action(..)) contained in emails that will be sent by the service).

I do not want to hardcode the links into the emails - they should be resolved using the urlhelper.

The job:

public class EvaluateRequestsJob : Quartz.IJob
{
    public void Execute(JobExecutionContext context)
    {
        //  where to get a usable urlHelper instance?
        ServiceFactory.GetRequestService(urlHelper).RunEvaluation();
    }
}

Please note that this is not run within the MVC pipeline. There is no current request being served, the code is run by the Quartz scheduler at defined times.

How do I get a UrlHelper instance usable on the indicated place?

If it is not possible to construct a UrlHelper, the other option I see is to make the job "self-call" a controller action by doing a HTTP request - while executing the action I will of course have a UrlHelper instance available - but this seems a little bit hacky to me.

© Stack Overflow or respective owner

Related posts about quartz.net

Related posts about quartz-scheduler