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?
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.