diff --git a/src/Microsoft.AspNet.Mvc.Core/ActionResults/CreatedAtRouteResult.cs b/src/Microsoft.AspNet.Mvc.Core/ActionResults/CreatedAtRouteResult.cs
index 87491c4bec..10667350f8 100644
--- a/src/Microsoft.AspNet.Mvc.Core/ActionResults/CreatedAtRouteResult.cs
+++ b/src/Microsoft.AspNet.Mvc.Core/ActionResults/CreatedAtRouteResult.cs
@@ -60,10 +60,9 @@ namespace Microsoft.AspNet.Mvc
///
protected override void OnFormatting([NotNull] ActionContext context)
{
- var request = context.HttpContext.Request;
var urlHelper = UrlHelper ?? context.HttpContext.RequestServices.GetRequiredService();
- var url = urlHelper.RouteUrl(RouteName, RouteValues, request.Scheme, request.Host.ToUriComponent());
+ var url = urlHelper.Link(RouteName, RouteValues);
if (string.IsNullOrEmpty(url))
{
diff --git a/src/Microsoft.AspNet.Mvc.Core/IUrlHelper.cs b/src/Microsoft.AspNet.Mvc.Core/IUrlHelper.cs
index 81f2251bff..867fcd189c 100644
--- a/src/Microsoft.AspNet.Mvc.Core/IUrlHelper.cs
+++ b/src/Microsoft.AspNet.Mvc.Core/IUrlHelper.cs
@@ -55,5 +55,16 @@ namespace Microsoft.AspNet.Mvc
/// The context object for the generated URLs for a route.
/// The fully qualified or absolute URL.
string RouteUrl([NotNull] UrlRouteContext routeContext);
+
+ ///
+ /// Generates an absolute URL using the specified route name and values.
+ ///
+ /// The name of the route that is used to generate the URL.
+ /// An object that contains the route values.
+ /// The generated absolute URL.
+ ///
+ /// The protocol and host is obtained from the current request.
+ ///
+ string Link(string routeName, object values);
}
}
diff --git a/src/Microsoft.AspNet.Mvc.Core/UrlHelper.cs b/src/Microsoft.AspNet.Mvc.Core/UrlHelper.cs
index 607c8d7cba..7d194276a9 100644
--- a/src/Microsoft.AspNet.Mvc.Core/UrlHelper.cs
+++ b/src/Microsoft.AspNet.Mvc.Core/UrlHelper.cs
@@ -127,6 +127,18 @@ namespace Microsoft.AspNet.Mvc
return GenerateClientUrl(_httpContext.Request.PathBase, contentPath);
}
+ ///
+ public virtual string Link(string routeName, object values)
+ {
+ return RouteUrl(new UrlRouteContext()
+ {
+ RouteName = routeName,
+ Values = values,
+ Protocol = _httpContext.Request.Scheme,
+ Host = _httpContext.Request.Host.ToUriComponent()
+ });
+ }
+
private static string GenerateClientUrl([NotNull] PathString applicationPath,
[NotNull] string path)
{
diff --git a/test/Microsoft.AspNet.Mvc.Core.Test/ActionResults/CreatedAtRouteResultTests.cs b/test/Microsoft.AspNet.Mvc.Core.Test/ActionResults/CreatedAtRouteResultTests.cs
index 320bfc0503..c6a258bc6a 100644
--- a/test/Microsoft.AspNet.Mvc.Core.Test/ActionResults/CreatedAtRouteResultTests.cs
+++ b/test/Microsoft.AspNet.Mvc.Core.Test/ActionResults/CreatedAtRouteResultTests.cs
@@ -115,7 +115,7 @@ namespace Microsoft.AspNet.Mvc
private static IUrlHelper GetMockUrlHelper(string returnValue)
{
var urlHelper = new Mock();
- urlHelper.Setup(o => o.RouteUrl(It.IsAny())).Returns(returnValue);
+ urlHelper.Setup(o => o.Link(It.IsAny(), It.IsAny