Feature suggestion: Absolute URLs without HttpContext and/or UrlHelper

May 23, 2013 at 3:11 PM
I'm using FluentScheduler to send some HTML emails (using RazorEngine) from a background task. It was a pain to make it work. One problem was that I needed to resolve absolute URLs, but in different thread (so without HttpContext and UrlHelper)

I found a simple an elegant solution. I edit it by hand now, but I think it will be a great feature to integrate directly into T4MVC. I have posted it on my GIST https://gist.github.com/dhlavaty/5636215

What do you think ?
Coordinator
May 23, 2013 at 10:04 PM
One concern is that I think it is hard for this to be completely correct in the general case, because routing can be so flexible. e.g. you could end up using a different route by simply passing a different value to a route parameter (depending on route constraints). Without true routing, you'd need to precook the shape of the URL, which would use those subtleties.
May 24, 2013 at 7:04 AM
I agree, it is not a 100% solution for all cases. But it helps for maybe 90% of them. And we can try to figure out a solution for the rest 10%. Maybe by annotating an action methods with a custom attributes, to say T4MVC what kind of URL we need to generate. It is just my first idea.

Although I think it will solve a lot of problems people had (including me). I saw a lot of questions on StackOverflow.com that can be solved with it.
May 29, 2013 at 6:54 PM
I kind of like this idea, if it was coded into T4MVC somehow? I have not yet gotten to needing this, but I know I will as we use T4MVC more and need a way to generate action links etc for HTML emails in our data access layers, which won't have any connection to the current context? Especially if they run off-line, in background tasks at night.

Athough accessing the main MVC object is probably not possible either as it would bring in the entire MVC library, so maybe it needs to be generated as a separate class, that can be used to generate something for off-line use. In which case maybe this is a cool project, but a side T4 template to the main T4MVC one :)
Coordinator
May 29, 2013 at 8:07 PM
I have to say I'm not a huge fan of the idea. If MVC itself had a way to build routes outside of a request, and then we could build on top of that.
May 29, 2013 at 9:15 PM
True, it would only work in the limited context of knowing in advance how the routing works. Which would probably be enough for the specialized cases the original poster needed it in (and what I would need it for), but it would break if someone changes the routing.
May 31, 2013 at 2:39 PM
As KendallB wrote, generating action links for HTML emails in my application service layer was a big problem. So I came with this solution. It's not perfect, but works. (Just to notice, I have also another problem with it on Azure. You cannot run Initialization on the first request, because first request is usually fired in staging environment with wrong domain name. But luckily solution to that is very simple.)

And I agree, that this should be a side T4 template to the main T4MVC.
Coordinator
May 31, 2013 at 5:39 PM
I like the idea of making this a side template, at least initially.
Jun 11, 2013 at 7:22 PM
Maybe call it T4MVCEmail or something ;)