Reputation: 2526
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!
Upvotes: 2
Views: 414
Reputation: 7517
Here are two options you can try:
HostingEnvironment.MapPath()
System.Web.Mvc.UrlHelper
in your API controllerUpvotes: 0
Reputation: 3959
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.
Upvotes: 1