ASP.NET MVC: Is it good to access HttpContext in a controller?

Posted by Zach on Stack Overflow See other posts from Stack Overflow or by Zach
Published on 2012-04-07T10:35:18Z Indexed on 2012/04/07 11:29 UTC
Read the original article Hit count: 330

Filed under:
|
|

I've been working with ASP.NET(WebForm) for a while, but new to ASP.NET MVC. From many articles I've read, in most cases the reason that the controllers are hard to test is because they are accessing the runtime components: HttpContext (including Request, Response ...). Accessing HttpContext in a controller seems bad.

However, I must access these components somewhere, reading input from Request, sending results back via Response, and using Session to hold a few state variables.

So where is the best place to access these runtime components if we don't access them in a controller?

Best regards, Zach@Shine

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about mvc