Where to use Controller.HttpContext
Posted
by Ben
on Stack Overflow
See other posts from Stack Overflow
or by Ben
Published on 2010-03-23T19:38:32Z
Indexed on
2010/03/23
19:43 UTC
Read the original article
Hit count: 747
asp.net-mvc
|httpcontext
Hi,
In my base controller's constructor I am calling an extension method that checks for specific cookies on the client.
Currently I am using System.Web.HttpContext.Current to get the current context.
However, I am lead to believe that I should be using Controller.HttpContext since it is more testable and contains additional information about the request.
However, Controller.HttpContext returns null on creation (believe this is by design) but also on Initialize and Execute methods (unless I use Routing.RequestContext.HttpContext?).
So if I should be using Controller.HttpContext instead of HttpContext.Current, at what point is it available to me in a request?
Thanks Ben
© Stack Overflow or respective owner