added checks to ensure http context exists before accessing (think command line, tasks etc)