Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 632
Natalie Perret Avatar asked Nov 21 '17 10:11

Natalie Perret


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;
like image 59
MarkovskI Avatar answered Sep 19 '22 18:09

MarkovskI