本文介绍了有没有办法在 Quartz.NET 作业中访问 HttpContext 对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有什么方法可以从 Quartz.NET 作业中访问 HttpContext 对象?HttpContext.Current 等似乎不适用于 Quartz.NET 作业.
Is there any way to gain access to the HttpContext object from a Quartz.NET job? HttpContext.Current and the likes do not seem to work with Quartz.NET jobs.
推荐答案
是的,有办法.
像这样实例化新调度程序(可能在 Global.asax 的 Application_Start 事件中)时,只需将 HttpContext.Current 设置为 JobDataMap:
Yes there is a way.
Just set HttpContext.Current to JobDataMap when instantiating new scheduler(probably in Application_Start event in Global.asax) like this:
jobDetail.JobDataMap["context"] = HttpContext.Current;
然后像这样在 Execute 方法中访问它:
Then access it in Execute method like this:
HttpContext context = context.JobDetail.JobDataMap["context"] as HttpContext;
这篇关于有没有办法在 Quartz.NET 作业中访问 HttpContext 对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!