HangfireIO / Hangfire

An easy way to perform background job processing in .NET and .NET Core applications. No Windows Service or separate process required
https://www.hangfire.io
Other
9.35k stars 1.69k forks source link

Unable to obtain http context #2442

Open Brawns opened 3 weeks ago

Brawns commented 3 weeks ago

How to solve the problem that the scheduled task executed by Hangfire cannot obtain the http context of the original request, and some interfaces assigned according to the http context cannot obtain the value in the method executed by Hangfire

BredStik commented 3 days ago

You should capture the values you need from the HttpContext in an object and use it as a parameter when scheduling the Hangfire task. HttpContext is never accessible outside of the original request.