2

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
  • 2
    Because they do not run in a web process (they run outside of the IIS) Commented Sep 6, 2017 at 7:31
  • Thanks robert for quick reply. Your answer make the sense but can you please give more information.
    – Curious
    Commented Sep 6, 2017 at 7:36

1 Answer 1

4

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.

2
  • 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
    Commented Sep 7, 2017 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. Commented Sep 7, 2017 at 9:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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