What is the difference between Url.RouteUrl and Url.HttpRouteUrl?

 Posted by Sheonarayan on 5/15/2014 | Category: ASP.NET MVC Interview questions | Views: 18743 | Points: 40

Url.RouteUrl is used to generate a fully qualified URL for specified route values by using a route name configured in App_Start/RouteConfig.cs file.

@Url.RouteUrl("MyCustomRoute", new { action = "New", id = 12, Name = "Sheo" })
gives output as /CustomController/New/12?Name=Sheo

Url.HttpRouteUrl is also used to generate fully qualified URL for the specified route values but for Web API Routes. Internally this method add an "httproute" entry to routeValues. GetVirtualPath method of the Web Api route classes return null unless we include "httproute" in the values.
@Url.HttpRouteUrl("MyCustomRoute", new { action = "New", id = 12, Name = "Sheo" })</p>
gives output as /CustomController/New/12?Name=Sheo&httproute=True.

Notice httproute query-string at the end.

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response