Reputation: 9500
In old MVC5/WebApi there was UrlHelper
with static methods: GenerateContentUrl
and GenerateUrl
.
GenerateContentUrl was useful for getting url to app root:
var root = UrlHelper.GenerateContentUrl("~", context /*HttpContext*/);
In MVC 6 (ASP.NET 5) we still have UrlHelper
class. But there are no static methods in it.
So what to use instead?
Upvotes: 2
Views: 1331
Reputation: 57949
You can use the Content
method on UrlHelper
Example(from within a controller where Url property represents a UrlHelper): Url.Content("~/scripts/bootstrap.min.css");
A UrlHelper instance is created per-request and it gets the information about the application root path through the http context that gets injected into it.
Upvotes: 3