How do I get an HttpContext object from HttpContextBase in ASP.NET MVC 1?

后端 未结 3 749
故里飘歌
故里飘歌 2020-12-04 11:40

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

3条回答
  •  攒了一身酷
    2020-12-04 12:17

    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.

提交回复
热议问题