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.43k stars 1.7k forks source link

Unable to obtain http context #2442

Open Brawns opened 2 months ago

Brawns commented 2 months 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 1 month 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.