没有HTTPContext的MVC 5 UrlHelper?

时间:2017-05-03 21:40:35

标签: asp.net-mvc httpcontext hangfire

我用路由属性装饰我的MVC 5动作:

[Route("this-test")] 
public ActionResult ThisTest()

并且使用HTTPContext我可以像这样访问路由名称:

UrlHelper helper = new UrlHelper(System.Web.HttpContext.Current.Request.RequestContext);
string actionUrl = helper.Action("ThisTest", "Home");

但是我使用Hangfire chron作业来发送一些电子邮件。由于我没有HTTPContext,因此我无法使用上面的代码来获取我的路线" home / this-test /"。

这有可能实现吗?谢谢。

1 个答案:

答案 0 :(得分:0)

看看这个主题: Passing site URL to hangfire recurrent jobs

依靠那里的答案,无法在Hangfire工作中接收域名。将您网站的网址作为参数传递给作业似乎是最明确的解决方案。