The problem I am facing with my Console App that is running in Microsoft Azure WebJobs is that HttpContext.Current is not evaluating to null. In other words, When I do the following, UserID is read from HttpContext.Current.User.Identity.GetUserId(), which evaluates to “”.
string UserID = HttpContext.Current == null ? App.UserID : HttpContext.Current.User.Identity.GetUserId();
Please note that I am calling this code from my MVC 5 Web App as well and this is why I am performing the above check.
The strange thing here is that when I run the console app from my local machine, HttpContext.Current evaluates to null and works as expected. This is only happening in Microsoft Azure WebJobs.
This code is developed in .NET Framework 4.5.2.
Any idea how I can fix this or how I can remote debug a WebJob console app using Visual Studio?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Turns out it was not the console app that was causing the issue. The console app updated Google Calendar which triggered a webhook notification. This webhook notification was populating the HttpContext.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0