diff --git a/src/Microsoft.AspNet.Mvc.Core/IUrlHelper.cs b/src/Microsoft.AspNet.Mvc.Core/IUrlHelper.cs
index 9c466cdfbe..81f2251bff 100644
--- a/src/Microsoft.AspNet.Mvc.Core/IUrlHelper.cs
+++ b/src/Microsoft.AspNet.Mvc.Core/IUrlHelper.cs
@@ -9,17 +9,12 @@ namespace Microsoft.AspNet.Mvc
public interface IUrlHelper
{
///
- /// Generates a fully qualified or absolute URL for an action method by using the specified action name,
- /// controller name, route values, protocol to use, host name and fragment.
+ /// Generates a fully qualified or absolute URL specified by for an action
+ /// method, which contains action name, controller name, route values, protocol to use, host name, and fragment.
///
- /// The name of the action method.
- /// The name of the controller.
- /// An object that contains the parameters for a route.
- /// The protocol for the URL, such as "http" or "https".
- /// The host name for the URL.
- /// The fragment for the URL.
+ /// The context object for the generated URLs for an action method.
/// The fully qualified or absolute URL to an action method.
- string Action(string action, string controller, object values, string protocol, string host, string fragment);
+ string Action([NotNull] UrlActionContext actionContext);
///
/// Converts a virtual (relative) path to an application absolute path.
@@ -54,15 +49,11 @@ namespace Microsoft.AspNet.Mvc
bool IsLocalUrl(string url);
///
- /// Generates a fully qualified or absolute URL for the specified route values by
- /// using the specified route name, protocol to use, host name and fragment.
+ /// Generates a fully qualified or absolute URL specified by , which
+ /// contains the route name, the route values, protocol to use, host name and fragment.
///
- /// The name of the route that is used to generate URL.
- /// An object that contains the parameters for a route.
- /// The protocol for the URL, such as "http" or "https".
- /// The host name for the URL.
- /// The fragment for the URL.
+ /// The context object for the generated URLs for a route.
/// The fully qualified or absolute URL.
- string RouteUrl(string routeName, object values, string protocol, string host, string fragment);
+ string RouteUrl([NotNull] UrlRouteContext routeContext);
}
}
diff --git a/src/Microsoft.AspNet.Mvc.Core/RemoteAttribute.cs b/src/Microsoft.AspNet.Mvc.Core/RemoteAttribute.cs
index e8daaf395e..d56364a03c 100644
--- a/src/Microsoft.AspNet.Mvc.Core/RemoteAttribute.cs
+++ b/src/Microsoft.AspNet.Mvc.Core/RemoteAttribute.cs
@@ -193,7 +193,12 @@ namespace Microsoft.AspNet.Mvc
protected virtual string GetUrl([NotNull] ClientModelValidationContext context)
{
var urlHelper = context.RequestServices.GetRequiredService();
- var url = urlHelper.RouteUrl(RouteName, values: RouteData, protocol: null, host: null, fragment: null);
+ var url = urlHelper.RouteUrl(new UrlRouteContext()
+ {
+ RouteName = this.RouteName,
+ Values = RouteData,
+ });
+
if (url == null)
{
throw new InvalidOperationException(Resources.RemoteAttribute_NoUrlFound);
diff --git a/src/Microsoft.AspNet.Mvc.Core/UrlActionContext.cs b/src/Microsoft.AspNet.Mvc.Core/UrlActionContext.cs
new file mode 100644
index 0000000000..db255f4bbc
--- /dev/null
+++ b/src/Microsoft.AspNet.Mvc.Core/UrlActionContext.cs
@@ -0,0 +1,67 @@
+// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
+// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
+
+namespace Microsoft.AspNet.Mvc
+{
+ ///
+ /// Context object to be used for the URLs that generates.
+ ///
+ public class UrlActionContext
+ {
+ ///
+ /// The name of the action method that
+ public string Action
+ {
+ get;
+ set;
+ }
+
+ ///
+ /// The name of the controller that
+ public string Controller
+ {
+ get;
+ set;
+ }
+
+ ///
+ /// The object that contains the route parameters that
+ /// uses to generate URLs.
+ ///
+ public object Values
+ {
+ get;
+ set;
+ }
+
+ ///
+ /// The protocol for the URLs that
+ public string Protocol
+ {
+ get;
+ set;
+ }
+
+ ///
+ /// The host name for the URLs that
+ public string Host
+ {
+ get;
+ set;
+ }
+
+ ///
+ /// The fragment for the URLs that
+ public string Fragment
+ {
+ get;
+ set;
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Microsoft.AspNet.Mvc.Core/UrlHelper.cs b/src/Microsoft.AspNet.Mvc.Core/UrlHelper.cs
index e463fcea99..607c8d7cba 100644
--- a/src/Microsoft.AspNet.Mvc.Core/UrlHelper.cs
+++ b/src/Microsoft.AspNet.Mvc.Core/UrlHelper.cs
@@ -40,24 +40,18 @@ namespace Microsoft.AspNet.Mvc
}
///
- public virtual string Action(
- string action,
- string controller,
- object values,
- string protocol,
- string host,
- string fragment)
+ public virtual string Action(UrlActionContext actionContext)
{
- var valuesDictionary = TypeHelper.ObjectToDictionary(values);
+ var valuesDictionary = TypeHelper.ObjectToDictionary(actionContext.Values);
- if (action != null)
+ if (actionContext.Action != null)
{
- valuesDictionary["action"] = action;
+ valuesDictionary["action"] = actionContext.Action;
}
- if (controller != null)
+ if (actionContext.Controller != null)
{
- valuesDictionary["controller"] = controller;
+ valuesDictionary["controller"] = actionContext.Controller;
}
var path = GeneratePathFromRoute(valuesDictionary);
@@ -66,7 +60,7 @@ namespace Microsoft.AspNet.Mvc
return null;
}
- return GenerateUrl(protocol, host, path, fragment);
+ return GenerateUrl(actionContext.Protocol, actionContext.Host, path, actionContext.Fragment);
}
///
@@ -76,17 +70,17 @@ namespace Microsoft.AspNet.Mvc
}
///
- public virtual string RouteUrl(string routeName, object values, string protocol, string host, string fragment)
+ public virtual string RouteUrl(UrlRouteContext routeContext)
{
- var valuesDictionary = TypeHelper.ObjectToDictionary(values);
+ var valuesDictionary = TypeHelper.ObjectToDictionary(routeContext.Values);
- var path = GeneratePathFromRoute(routeName, valuesDictionary);
+ var path = GeneratePathFromRoute(routeContext.RouteName, valuesDictionary);
if (path == null)
{
return null;
}
- return GenerateUrl(protocol, host, path, fragment);
+ return GenerateUrl(routeContext.Protocol, routeContext.Host, path, routeContext.Fragment);
}
private string GeneratePathFromRoute(IDictionary values)
diff --git a/src/Microsoft.AspNet.Mvc.Core/UrlHelperExtensions.cs b/src/Microsoft.AspNet.Mvc.Core/UrlHelperExtensions.cs
index 44e12ddbac..d07aea6756 100644
--- a/src/Microsoft.AspNet.Mvc.Core/UrlHelperExtensions.cs
+++ b/src/Microsoft.AspNet.Mvc.Core/UrlHelperExtensions.cs
@@ -5,6 +5,10 @@ namespace Microsoft.AspNet.Mvc
{
public static class UrlHelperExtensions
{
+ ///
+ /// Generates a fully qualified or absolute URL for an action method.
+ ///
+ /// The fully qualified or absolute URL to an action method.
public static string Action([NotNull] this IUrlHelper helper)
{
return helper.Action(
@@ -16,26 +20,62 @@ namespace Microsoft.AspNet.Mvc
fragment: null);
}
+ ///
+ /// Generates a fully qualified or absolute URL for an action method by using the specified action name.
+ ///
+ /// The name of the action method.
+ /// The fully qualified or absolute URL to an action method.
public static string Action([NotNull] this IUrlHelper helper, string action)
{
return helper.Action(action, controller: null, values: null, protocol: null, host: null, fragment: null);
}
+ ///
+ /// Generates a fully qualified or absolute URL for an action method by using the specified action name,
+ /// and route values.
+ ///
+ /// The name of the action method.
+ /// An object that contains route values.
+ /// The fully qualified or absolute URL to an action method.
public static string Action([NotNull] this IUrlHelper helper, string action, object values)
{
return helper.Action(action, controller: null, values: values, protocol: null, host: null, fragment: null);
}
+ ///
+ /// Generates a fully qualified or absolute URL for an action method by using the specified action name,
+ /// and controller name.
+ ///
+ /// The name of the action method.
+ /// The name of the controller.
+ /// The fully qualified or absolute URL to an action method.
public static string Action([NotNull] this IUrlHelper helper, string action, string controller)
{
return helper.Action(action, controller, values: null, protocol: null, host: null, fragment: null);
}
+ ///
+ /// Generates a fully qualified or absolute URL for an action method by using the specified action name,
+ /// controller name, and route values.
+ ///
+ /// The name of the action method.
+ /// The name of the controller.
+ /// An object that contains route values.
+ /// The fully qualified or absolute URL to an action method.
public static string Action([NotNull] this IUrlHelper helper, string action, string controller, object values)
{
return helper.Action(action, controller, values, protocol: null, host: null, fragment: null);
}
+ ///
+ /// Generates a fully qualified or absolute URL for an action method by using the specified action name,
+ /// controller name, route values, and protocol to use.
+ ///
+ /// The name of the action method.
+ /// The name of the controller.
+ /// An object that contains route values.
+ /// The protocol for the URL, such as "http" or "https".
+ /// The fully qualified or absolute URL to an action method.
public static string Action(
[NotNull] this IUrlHelper helper,
string action,
@@ -46,6 +86,16 @@ namespace Microsoft.AspNet.Mvc
return helper.Action(action, controller, values, protocol, host: null, fragment: null);
}
+ ///
+ /// Generates a fully qualified or absolute URL for an action method by using the specified action name,
+ /// controller name, route values, protocol to use, and host name.
+ ///
+ /// The name of the action method.
+ /// The name of the controller.
+ /// An object that contains route values.
+ /// The protocol for the URL, such as "http" or "https".
+ /// The host name for the URL.
+ /// The fully qualified or absolute URL to an action method.
public static string Action(
[NotNull] this IUrlHelper helper,
string action,
@@ -57,21 +107,77 @@ namespace Microsoft.AspNet.Mvc
return helper.Action(action, controller, values, protocol, host, fragment: null);
}
+ ///
+ /// Generates a fully qualified or absolute URL for an action method by using the specified action name,
+ /// controller name, route values, protocol to use, host name and fragment.
+ ///
+ /// The name of the action method.
+ /// The name of the controller.
+ /// An object that contains route values.
+ /// The protocol for the URL, such as "http" or "https".
+ /// The host name for the URL.
+ /// The fragment for the URL.
+ /// The fully qualified or absolute URL to an action method.
+ public static string Action(
+ [NotNull] this IUrlHelper helper,
+ string action,
+ string controller,
+ object values,
+ string protocol,
+ string host,
+ string fragment)
+ {
+ return helper.Action(new UrlActionContext()
+ {
+ Action = action,
+ Controller = controller,
+ Host = host,
+ Values = values,
+ Protocol = protocol,
+ Fragment = fragment
+ });
+ }
+
+ ///
+ /// Generates a fully qualified or absolute URL for the specified route values.
+ ///
+ /// An object that contains route values.
+ /// The fully qualified or absolute URL.
public static string RouteUrl([NotNull] this IUrlHelper helper, object values)
{
return helper.RouteUrl(routeName: null, values: values, protocol: null, host: null, fragment: null);
}
+ ///
+ /// Generates a fully qualified or absolute URL for the specified route name.
+ ///
+ /// The name of the route that is used to generate URL.
+ /// The fully qualified or absolute URL.
public static string RouteUrl([NotNull] this IUrlHelper helper, string routeName)
{
return helper.RouteUrl(routeName, values: null, protocol: null, host: null, fragment: null);
}
+ ///
+ /// Generates a fully qualified or absolute URL for the specified route values by
+ /// using the specified route name.
+ ///
+ /// The name of the route that is used to generate URL.
+ /// An object that contains route values.
+ /// The fully qualified or absolute URL.
public static string RouteUrl([NotNull] this IUrlHelper helper, string routeName, object values)
{
return helper.RouteUrl(routeName, values, protocol: null, host: null, fragment: null);
}
+ ///
+ /// Generates a fully qualified or absolute URL for the specified route values by
+ /// using the specified route name, and protocol to use.
+ ///
+ /// The name of the route that is used to generate URL.
+ /// An object that contains route values.
+ /// The protocol for the URL, such as "http" or "https".
+ /// The fully qualified or absolute URL.
public static string RouteUrl(
[NotNull] this IUrlHelper helper,
string routeName,
@@ -81,6 +187,15 @@ namespace Microsoft.AspNet.Mvc
return helper.RouteUrl(routeName, values, protocol, host: null, fragment: null);
}
+ ///
+ /// Generates a fully qualified or absolute URL for the specified route values by
+ /// using the specified route name, protocol to use, and host name.
+ ///
+ /// The name of the route that is used to generate URL.
+ /// An object that contains route values.
+ /// The protocol for the URL, such as "http" or "https".
+ /// The host name for the URL.
+ /// The fully qualified or absolute URL.
public static string RouteUrl(
[NotNull] this IUrlHelper helper,
string routeName,
@@ -90,5 +205,33 @@ namespace Microsoft.AspNet.Mvc
{
return helper.RouteUrl(routeName, values, protocol, host, fragment: null);
}
+
+ ///
+ /// Generates a fully qualified or absolute URL for the specified route values by
+ /// using the specified route name, protocol to use, host name and fragment.
+ ///
+ /// The name of the route that is used to generate URL.
+ /// An object that contains route values.
+ /// The protocol for the URL, such as "http" or "https".
+ /// The host name for the URL.
+ /// The fragment for the URL.
+ /// The fully qualified or absolute URL.
+ public static string RouteUrl(
+ [NotNull] this IUrlHelper helper,
+ string routeName,
+ object values,
+ string protocol,
+ string host,
+ string fragment)
+ {
+ return helper.RouteUrl(new UrlRouteContext()
+ {
+ RouteName = routeName,
+ Values = values,
+ Protocol = protocol,
+ Host = host,
+ Fragment = fragment
+ });
+ }
}
}
diff --git a/src/Microsoft.AspNet.Mvc.Core/UrlRouteContext.cs b/src/Microsoft.AspNet.Mvc.Core/UrlRouteContext.cs
new file mode 100644
index 0000000000..7838fa11a6
--- /dev/null
+++ b/src/Microsoft.AspNet.Mvc.Core/UrlRouteContext.cs
@@ -0,0 +1,57 @@
+// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
+// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
+
+namespace Microsoft.AspNet.Mvc
+{
+ ///
+ /// Context object to be used for the URLs that generates.
+ ///
+ public class UrlRouteContext
+ {
+ ///
+ /// The name of the route that
+ public string RouteName
+ {
+ get;
+ set;
+ }
+
+ ///
+ /// The object that contains the route values for the generated URLs.
+ ///
+ public object Values
+ {
+ get;
+ set;
+ }
+
+ ///
+ /// The protocol for the URLs that
+ public string Protocol
+ {
+ get;
+ set;
+ }
+
+ ///
+ /// The host name for the URLs that
+ public string Host
+ {
+ get;
+ set;
+ }
+
+ ///
+ /// The fragment for the URLs that
+ public string Fragment
+ {
+ get;
+ set;
+ }
+ }
+}
\ No newline at end of file
diff --git a/test/Microsoft.AspNet.Mvc.Core.Test/ActionResults/CreatedAtActionResultTests.cs b/test/Microsoft.AspNet.Mvc.Core.Test/ActionResults/CreatedAtActionResultTests.cs
index 04d81201b9..0214712d41 100644
--- a/test/Microsoft.AspNet.Mvc.Core.Test/ActionResults/CreatedAtActionResultTests.cs
+++ b/test/Microsoft.AspNet.Mvc.Core.Test/ActionResults/CreatedAtActionResultTests.cs
@@ -106,8 +106,7 @@ namespace Microsoft.AspNet.Mvc
private static IUrlHelper GetMockUrlHelper(string returnValue)
{
var urlHelper = new Mock();
- urlHelper.Setup(o => o.Action(It.IsAny(), It.IsAny(), It.IsAny