我使用的是hangfire,DI使用的是autofac。我想使用postal.mvc5工具发送电子邮件,但收到以下错误:
System.InvalidOperationException
The request lifetime scope cannot be created because the HttpContext is not available.
System.InvalidOperationException: The request lifetime scope cannot be created because the HttpContext is not available.
at Autofac.Integration.Mvc.RequestLifetimeScopeProvider.GetLifetimeScope(Action`1 configurationAction)
at Autofac.Integration.Mvc.AutofacDependencyResolver.get_RequestLifetimeScope()
at Autofac.Integration.Mvc.AutofacDependencyResolver.GetService(Type serviceType)
at System.Web.Mvc.BuildManagerViewEngine.DefaultViewPageActivator.Create(ControllerContext controllerContext, Type type)
at System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer)
at Postal.EmailViewRenderer.RenderView(IView view, ViewDataDictionary viewData, ControllerContext controllerContext, ImageEmbedder imageEmbedder)
at Postal.EmailViewRenderer.Render(Email email, String viewName)
at Postal.EmailService.Send(Email email)
at Postal.Email.Send()
at Store.Web.Controllers.HomeController.Test() in C:\Users\a\Documents\Visual Studio 2015\Projects\In\S.Web\Controllers\HomeController.cs:line 33我搜索了2天,没有找到关于这个问题的任何东西。请帮帮我!谢谢
发布于 2017-01-02 19:15:21
http://docs.hangfire.io/en/latest/tutorials/send-email.html#installing-postal
从上面的链接中解释。您不能使用Viewbag或template在httpcontext之外发送电子邮件。您必须使用模型而不是Viewbag,嵌入的图像也不能使用(请参阅http://aboutcode.net/postal/outside-aspnet.html)
对于嵌入的图像,您可以通过模型传递,请参阅此处以获得更多解释https://github.com/andrewdavey/postal/issues/44
https://stackoverflow.com/questions/34331291
复制相似问题