开发者

Render a view for an email in Asp.Net MVC 2 in a background service

I need to render a view to send as an email using Asp.Net MVC 2.

Using the new Html.Partial method it is easy to render a view to a string and then send it as an email as long as you do it from inside a controller or a view (where you can access the html helper or the controller context)

I need to be able to send a delayed email using a background service. I want to render them in the same way as I would开发者_开发百科 in a controller but I can't access the Html Helper or the controller context.

I tried to make my own method using the ViewPage class and calling its render method myslef passing in a stringwriter. Problem is that I don't have a view context for the html helper, so I can only render views that don't use the html helper or the url helper.

Any Ideas.

Thanks


MVCContrib has something that may help you

http://github.com/mvccontrib/MvcContrib/blob/master/src/MVCContrib/Services/EmailTemplateService.cs


ThreadPool.RegisterWaitForSingleObject(new ManualResetEvent(false), 
    (state, timeout) => 
    {
        var context = (HttpContext)state;
        // Use the context here
    }, HttpContext, TimeSpan.FromSeconds(10), true);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜