Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I convert an HttpRequest into an HttpRequestBase object?

My problem is the opposite of this: How do I convert an HttpRequestBase into an HttpRequest object?

In my ASP.NET MVC application I have a method used by many controllers that receive an HttpRequestBase as argument.

Now I have to call that method from another method, that is not an action (it's an nhibernate interceptor). In this second method I could access HttpContext.Current.Request, that is a HttpRequest and I cannot cast it to HttpRequestBase (I thought it was possibile due to the naming ...).

Does someone know in what relationship are this classes and how can I solve my problem? Thank you.

like image 897
Daniele Armanasco Avatar asked Mar 07 '13 15:03

Daniele Armanasco


1 Answers

You'll want to wrap your HttpRequest in a HttpRequestWrapper:

var wrapper = new HttpRequestWrapper(httpRequest); 

The HttpRequestWrapper inherits from HttpRequestBase.

like image 187
Jamie Dixon Avatar answered Sep 17 '22 16:09

Jamie Dixon