ASP.NET MVC: How to Create Your Own HttpContext

My idea was to create my own HttpContext, which would include some of the internal objects used in our application. So I thought I’d just create

public class FooHttpContextBase : HttpContextBase
{
    public string Foo
    {
        get { return "Boo"; }
    }
}

And then override the HttpContext property:

public abstract class BaseController : Controller
{
    private FooHttpContextBase context;

    public BaseController()
    {
        context = new FooHttpContextBase();
    }

    override public HttpContextBase HttpContext
    {
        get { return context; }
    }
}

But then I realized that the HttpContext is not virtual - so it cannot be redefined.

What are you offering? Add new property to BaseController?

Thanks in advance!

+1
source share
1 answer

, . , .
- IOC, , . .

-7

All Articles