我已尝试将其他解决方案发布到stackoverflow并且发现没有任何工作,这是我的问题.
所以我想通过我的MVC应用程序使用hangfire发送电子邮件,这可以在我的本地计算机上运行但是当我将它上传到远程服务器时,我在hangfire上收到以下错误:
The virtual path '/' maps to another application,which is not allowed
foreach (var EmailEntry in EmailEntries) { var email = new EmailTemplateModel { ViewName = "EmailTemplateModel",FromAddress = "donotreply@emailservice.com",EmailAddress = EmailEntry,Subject = "Task Report",Date = Dates,Task = DatesAndTasks,}; email.Send(); }
当我使用’ViewName’方法时,它在我的本地机器上返回’〜/ Views / Emails’.
在Send()方法内部:
// Summary: // Convenience method that sends this email via a default EmailService. public void Send();
IIS中的应用程序结构:
服务器>网站>默认>我的应用程序
JodyL的解决方案提出的问题如下:
StructureMapDependencyScope.get_CurrentnestedContainer()
解:
在“StructureMapDependencyScope”类中编辑了以下代码:
之前:
public IContainer CurrentnestedContainer { get { return (IContainer)HttpContext.Items[nestedContainerKey]; } set { HttpContext.Items[nestedContainerKey] = value; } }
后:
public IContainer CurrentnestedContainer { get { IContainer container = null; if (HttpContext != null) container = (IContainer)HttpContext.Items[nestedContainerKey]; return container; } set { HttpContext.Items[nestedContainerKey] = value; } }
之前:
private HttpContextBase HttpContext { get { var ctx = Container.TryGetInstance<HttpContextBase>(); return ctx ?? new HttpContextwrapper(System.Web.HttpContext.Current); } }
后:
private HttpContextBase HttpContext { get { var ctx = Container.TryGetInstance<HttpContextBase>(); if (ctx == null && System.Web.HttpContext.Current == null) return null; return ctx ?? new HttpContextwrapper(System.Web.HttpContext.Current); } }
解决方法
此问题可能是由于使用Hangfire时邮件无法使用HTTPContext引起的.如果HTTPContext.Current为null,则Postal使用
http://localhost作为URL,该URL不会映射到您的应用程序位置.为了解决此问题,您可以在发送电子邮件时使用FileSystemRazorViewEngine并将其传递给电子邮件模板的路径.
有关如何实现此目的的详细信息,请参阅此问题的答案.
Using Postal and Hangfire in Subsite
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。