I\'m working with some WebForms/MVC-agnostic tools, and I need to get an instance of HttpContext
given a reference to an HttpContextBase
object. I
You can't.
The whole purpose of HttpContextBase
is to abstract away the dependency on the concrete HttpContext
class. While it may contain a concrete HttpContext
(such as is the case with httpContextWrapper
), other implementations may have absolutely nothing to do with HttpContext
.
Your best option is to define a custom Abstract Factory that can get a HttpContextBase
for you, since you can always wrap a concrete HttpContext
in a HttpContextWrapper
.