c#+编码后的服务器虚拟路径,在C#中虚拟路径’/’映射到另一个应用程序,这是不允许的. MVC和Hangfire...

我已尝试将其他解决方案发布到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 = "[email protected]",

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()

wzvBj.png

解:

在“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();

return ctx ?? new HttpContextWrapper(System.Web.HttpContext.Current);

}

}

后:

private HttpContextBase HttpContext {

get {

var ctx = Container.TryGetInstance();

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值