我使用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天,没有发现这个问题。请帮我!感谢
答案 0 :(得分:0)
http://docs.hangfire.io/en/latest/tutorials/send-email.html#installing-postal
作为上述链接的解释。您不能使用Viewbag或模板在httpcontext之外发送电子邮件。您必须使用Model而不是Viewbag,并且嵌入的图像也不能(参考http://aboutcode.net/postal/outside-aspnet.html)
对于嵌入式图像,您可以通过模型,请参阅此处以获取更多解释https://github.com/andrewdavey/postal/issues/44