How do I convert an HttpRequestBase into an HttpRequest object?

Pure.Krome picture Pure.Krome · Sep 21, 2009 · Viewed 74.4k times · Source

inside my ASP.NET MVC controller, I've got a method that requires an HttpRequest object. All I have access to is an HttpRequestBase object.

Is there anyway I can somehow convert this?

What can/should I do??

Answer

CountZero picture CountZero · Feb 27, 2013

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);