Why the HttpContext is null within event receivers, console applications and timer jobs.

HttpContext httpctx = HttpContext.Current;

I googled about it and found that its by design. But why by design? There should be specific reason or purpose behind it. As a newbie i just want to be more clear about sharepoint concepts. Thank you.

  • 2
    Because they do not run in a web process (they run outside of the IIS) – Robert Lindgren Sep 6 '17 at 7:31
  • Thanks robert for quick reply. Your answer make the sense but can you please give more information. – Curious Sep 6 '17 at 7:36

Think about what HTTP is and what an HTTP context would represent.

HTTP is the protocol that web servers use. Event receivers, timer jobs and console apps aren't served from a web server over HTTP. There's no request and no response, hence no HTTP context.

  • Thanks Derek for answer. Ok I understood the Console app is not running on web server, but then where actually the event receivers and timer jobs runs? because these are deployed on sharepoint site ! – Curious Sep 7 '17 at 5:32
  • They run in (non-web) separate process on the server. Timer jobs run on Owstimer.exe and event receivers run in a different process as well (can't remember which right now). Think of it this way: if it doesn't happen in a browser, it's (probably) not an HTTP context. – Derek Gusoff Sep 7 '17 at 9:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.