Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does HttpContext not derive from HttpContextBase?

Tags:

asp.net-mvc

Both have Request and Response properties, but I can't write a method that takes either HttpContext or HttpContextBase. In some places either one or the other is available so I need to handle both. I know HttpContextWrapper can convert in one direction, but still... why is it like this?

like image 913
JoelFan Avatar asked Dec 29 '09 05:12

JoelFan


1 Answers

HttpContext has been around since .NET 1.0. Because of backward compatibility reasons, they can't change that class. HttpContextBase was introduced in ASP.NET MVC to allow for better testability because it makes it easier to mock/stub it.

like image 149
Sander Rijken Avatar answered Sep 24 '22 15:09

Sander Rijken