2

I'm attempting to make a Virtual directory relative link to some unknown (to WebAPI) resource form an ApiController.

Example:

http://some/path/webapi/does/not/know

The WebAPI Url helper seems to be tightly coupled with Routing and does not have a Content() method like the MVC variant. I'm trying to avoid using any non-mockable HTTP context information to make this call (such as HttpContext.Current).

Thanks for the help!

1
  • 1
    Have you tried to just create a System.Web.Mvc.UrlHelper in your API controller in order to use the Content method? Commented May 17, 2013 at 13:48

2 Answers 2

1

You can always do,

var urlBuilder = new System.UriBuilder(Request.Url.AbsoluteUri) { Path = "webapi/does/not/know" };

var uri = urlBuilder.Uri

In that way, you don't need to rely on the UrlHelper. The base url is inferred from the current request.

Sign up to request clarification or add additional context in comments.

Comments

0

Here are two options you can try:

  1. HostingEnvironment.MapPath()
  2. Create a System.Web.Mvc.UrlHelper in your API controller

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.