How can I generate a URL by RouteName outside of a view or controller?
I want generate a URL by RouteName in a seperate class for an e-mail, but if I try to use UrlHelper.GenerateUrl. Then I don’t see where I can get rest of the parameters for this function.
You shouldn’t be needing/doing this. Urls should be generated only in the front layers where you have access to an HTTP context and passed to backed layers as arguments.
Of course you could always perform some horrible grotesque hack in your backend layer and hardcode some static
HttpContext.Currentin order to instantiate anUrlHelperand thus render your backed layers strongly coupled to the HTTP stack, making it impossible to be reused in isolation and unit tested.Oh and by the way checkout MvcMailer if you need to send emails in your application. This way you can define the email body as templates where you will have access to helpers and stuff and won’t need to perform the aformentioned grotesque hack.