
所以我想通过我的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
以上是内存溢出为你收集整理的c# – 虚拟路径’/’映射到另一个应用程序,这是不允许的. MVC和Hangfire全部内容,希望文章能够帮你解决c# – 虚拟路径’/’映射到另一个应用程序,这是不允许的. MVC和Hangfire所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)