.Net MVC C# HTTP Context

There is more than one way to get hold of the HTTP context in a controller:

    // Current via Controller context
    var ctr = ControllerContext;
    var contextBase = ctr.HttpContext.Request;

    // Get the request base
    var httpRequestBase = new HttpRequestWrapper(System.Web.HttpContext.Current.Request);

It’s going to be easier to unit test your code if you use ControllerContext.

Leave a Reply

Your email address will not be published. Required fields are marked *