0

I have a Web API v2 controller that makes a method call out to a service in the same project. The service uses the UrlHelper class to put together a URL however, the UrlHelper class needs the HttpRequestMessage in order to build the proper URL.

How can I obtain the HttpRequestMessage from within a class (my service) that is outside of the API controller? Can I pass the HttpRequestMessage into the service method? Is there another way to access from a global context?

I am using a self-hosted environment (OWIN).

webworm
  • 10,587
  • 33
  • 120
  • 217

1 Answers1

2
public class FooController : ApiController
{
    public IHttpActionResult BarAction()
    {
        UrlHelper urlHelper = GetUrlHelperFromWhereever();
        urlHelper.DoSomething( this.Request );
    }

this.Request is HttpRequestMessage: https://msdn.microsoft.com/en-us/library/system.web.http.apicontroller.request(v=vs.118).aspx#P:System.Web.Http.ApiController.Request

Dai
  • 141,631
  • 28
  • 261
  • 374