How can I get the HttpRequest object in an ApiController without using the HttpContext static class?

Viewed 3595

I am looking for a way to get the HttpRequest (not HttpRequestMessage) object without using the HttpContext static class in my ApiController:

HttpContext.Current.Request.GetOwinContext().Get<ApplicationRoleManager>()

Instead of what I can have in a regular Controller which is a regular property instance:

HttpContext.GetOwinContext().Get<ApplicationRoleManager>()

Is there a way to have something right from the instance of the ApiController?

1 Answers

You can use:

var context = Request.Properties["MS_HttpContext"] as HttpContext;

or for Web API:

var context = Request.Properties["MS_HttpContext"] as HttpContextWrapper;
Related