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?
You can use:
var context = Request.Properties["MS_HttpContext"] as HttpContext;
or for Web API:
var context = Request.Properties["MS_HttpContext"] as HttpContextWrapper;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With