How do I convert an HttpRequestBase into an HttpRequest object?

You should always use HttpRequestBase and HttpResponseBase in your application as opposed to the concrete versions which are impossible to test (without typemock or some other magic).

Simply use the HttpRequestWrapper class to convert as shown below.

var httpRequestBase = new HttpRequestWrapper(Context.Request);

Is it your method, so you can re-write it to take HttpRequestBase? If not, you can always get the current HttpRequest from HttpContext.Current.HttpRequest to pass on. However, I often wrap access to the HttpContext inside a class like mentioned in ASP.NET: Removing System.Web Dependencies for better unit testing support.


You can just use

System.Web.HttpContext.Current.Request

The key here is that you need the full namespace to get to the "correct" HttpContext.

I know it's been 4 years since this question was asked, but if this will help somebody, then here you go!

(Edit: I see that Kevin Hakanson already gave this answer...so hopefully my response will help those people who just read answers and not comments.) :)


To get HttpRequest in ASP.NET MVC4 .NET 4.5, you can do the following:

this.HttpContext.ApplicationInstance.Context.Request