Shrike
Shrike

Reputation: 9500

What is an analog of UrlHelper.GenerateContentUrl in ASP.NET 5

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

Answers (1)

Kiran
Kiran

Reputation: 57949

You can use the Content method on UrlHelper

https://github.com/aspnet/Mvc/blob/c1eea5b3fabb01d44fbf74f8fe64b4bd087bd576/src/Microsoft.AspNet.Mvc.Core/UrlHelper.cs#L123

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

Related Questions