Convert HttpRequestMessage to HttpRequest
You probably don't need to convert from HttpRequestMessage. There is another way:
var context = new HttpContextWrapper(HttpContext.Current);
HttpRequestBase request = context.Request;
Avi L
I'm a lead developer in the Software/Internet industry with vast experience as project manager, technical leader and senior developer from 1998. Rain-Maker, self-motivated, resourceful, adaptive, organized, passionate entrepreneur attitude with strong combination of business skills and hands on technical expertise. Specialties: A dynamic leader, great technical and architectural skills, confident, intuitive, high communication skills, Very creative and innovate personality and able to drive decisions and changes. Vast experience in online gaming, online commerce, development and project management.
Updated on July 09, 2022Comments
-
Avi L almost 2 years
I'm converting ASP.NET web application to MVC Web Api project. One of my methods expects
HttpRequest
class. However, Web Api controller holds onlyHttpRequestMessage
(this.Request
) object. Do you know how I can convertHttpRequestMessage
toHttpRequest
? -
Avi L about 11 yearsHow do I get an 'HttpRequestBase'? should I create one myself? (i.e. create new object and copy 'HttpRequestMessage' parameters to it)
-
sobelito over 10 yearsSystem.Web.HttpContext.Current.Request
-
Andy almost 8 yearsThis seems awfully like cheating to me but I'm forced to do it if I want to write functions that can be called from ASP.NET Web API controllers as well as ASP.NET MVC controllers. For the life of me I don't understand by web API couldn't just be built on top of MVC (so ApiController could be a subclass of a normal MVC Controller). Instead if you want to use MVC and API together you have to navigate between two parallel but incompatible worlds with the same concepts in each.
-
OutstandingBill about 6 yearsI've seen on the comments under another answer that you shouldn't use System.Web.HttpContext.Current in Web API projects - you can instead use
(HttpContextWrapper)Request.Properties["MS_HttpContext"]
-
CSharper over 5 yearsyou can get HttpRequestBase using
((HttpContextWrapper)Request.Properties["MS_HttpContext"]).Request