c# – 虚拟路径’/’映射到另一个应用程序,这是不允许的. MVC和H
发布时间:2020-12-15 22:50:24 所属栏目:百科 来源:网络整理
导读:我已尝试将其他解决方案发布到stackoverflow并且发现没有任何工作,这是我的问题. 所以我想通过我的MVC应用程序使用hangfire发送电子邮件,这可以在我的本地计算机上运行但是当我将它上传到远程服务器时,我在hangfire上收到以下错误: The virtual path '/' ma
我已尝试将其他解决方案发布到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并将其传递给电子邮件模板的路径.
有关如何实现此目的的详细信息,请参阅此问题的答案. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |