Change template -> pattern for MVC

This commit is contained in:
Ryan Nowak 2019-03-12 14:03:25 -07:00
parent e78a6521b9
commit 4b4614635f
9 changed files with 39 additions and 39 deletions

View File

@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Builder
{ {
public static class EndpointRouteBuilderExtensions public static class EndpointRouteBuilderExtensions
{ {
public static IEndpointConventionBuilder MapHello(this IEndpointRouteBuilder routes, string template, string greeter) public static IEndpointConventionBuilder MapHello(this IEndpointRouteBuilder routes, string pattern, string greeter)
{ {
if (routes == null) if (routes == null)
{ {
@ -25,7 +25,7 @@ namespace Microsoft.AspNetCore.Builder
.Build(); .Build();
return routes.Map( return routes.Map(
template, pattern,
"Hello " + greeter, "Hello " + greeter,
pipeline); pipeline);
} }

View File

@ -62,12 +62,12 @@ namespace Microsoft.AspNetCore.Builder
/// <summary> /// <summary>
/// Adds endpoints for controller actions to the <see cref="IEndpointRouteBuilder"/> and specifies a route /// Adds endpoints for controller actions to the <see cref="IEndpointRouteBuilder"/> and specifies a route
/// with the given <paramref name="name"/>, <paramref name="template"/>, /// with the given <paramref name="name"/>, <paramref name="pattern"/>,
/// <paramref name="defaults"/>, <paramref name="constraints"/>, and <paramref name="dataTokens"/>. /// <paramref name="defaults"/>, <paramref name="constraints"/>, and <paramref name="dataTokens"/>.
/// </summary> /// </summary>
/// <param name="routes">The <see cref="IEndpointRouteBuilder"/> to add the route to.</param> /// <param name="routes">The <see cref="IEndpointRouteBuilder"/> to add the route to.</param>
/// <param name="name">The name of the route.</param> /// <param name="name">The name of the route.</param>
/// <param name="template">The URL pattern of the route.</param> /// <param name="pattern">The URL pattern of the route.</param>
/// <param name="defaults"> /// <param name="defaults">
/// An object that contains default values for route parameters. The object's properties represent the /// An object that contains default values for route parameters. The object's properties represent the
/// names and values of the default values. /// names and values of the default values.
@ -83,7 +83,7 @@ namespace Microsoft.AspNetCore.Builder
public static void MapControllerRoute( public static void MapControllerRoute(
this IEndpointRouteBuilder routes, this IEndpointRouteBuilder routes,
string name, string name,
string template, string pattern,
object defaults = null, object defaults = null,
object constraints = null, object constraints = null,
object dataTokens = null) object dataTokens = null)
@ -98,7 +98,7 @@ namespace Microsoft.AspNetCore.Builder
var dataSource = GetOrCreateDataSource(routes); var dataSource = GetOrCreateDataSource(routes);
dataSource.AddRoute(new ConventionalRouteEntry( dataSource.AddRoute(new ConventionalRouteEntry(
name, name,
template, pattern,
new RouteValueDictionary(defaults), new RouteValueDictionary(defaults),
new RouteValueDictionary(constraints), new RouteValueDictionary(constraints),
new RouteValueDictionary(dataTokens))); new RouteValueDictionary(dataTokens)));
@ -106,13 +106,13 @@ namespace Microsoft.AspNetCore.Builder
/// <summary> /// <summary>
/// Adds endpoints for controller actions to the <see cref="IEndpointRouteBuilder"/> and specifies a route /// Adds endpoints for controller actions to the <see cref="IEndpointRouteBuilder"/> and specifies a route
/// with the given <paramref name="name"/>, <paramref name="areaName"/>, <paramref name="template"/>, /// with the given <paramref name="name"/>, <paramref name="areaName"/>, <paramref name="pattern"/>,
/// <paramref name="defaults"/>, <paramref name="constraints"/>, and <paramref name="dataTokens"/>. /// <paramref name="defaults"/>, <paramref name="constraints"/>, and <paramref name="dataTokens"/>.
/// </summary> /// </summary>
/// <param name="routes">The <see cref="IEndpointRouteBuilder"/> to add the route to.</param> /// <param name="routes">The <see cref="IEndpointRouteBuilder"/> to add the route to.</param>
/// <param name="name">The name of the route.</param> /// <param name="name">The name of the route.</param>
/// <param name="areaName">The area name.</param> /// <param name="areaName">The area name.</param>
/// <param name="template">The URL pattern of the route.</param> /// <param name="pattern">The URL pattern of the route.</param>
/// <param name="defaults"> /// <param name="defaults">
/// An object that contains default values for route parameters. The object's properties represent the /// An object that contains default values for route parameters. The object's properties represent the
/// names and values of the default values. /// names and values of the default values.
@ -129,7 +129,7 @@ namespace Microsoft.AspNetCore.Builder
this IEndpointRouteBuilder routes, this IEndpointRouteBuilder routes,
string name, string name,
string areaName, string areaName,
string template, string pattern,
object defaults = null, object defaults = null,
object constraints = null, object constraints = null,
object dataTokens = null) object dataTokens = null)
@ -150,7 +150,7 @@ namespace Microsoft.AspNetCore.Builder
var constraintsDictionary = new RouteValueDictionary(constraints); var constraintsDictionary = new RouteValueDictionary(constraints);
constraintsDictionary["area"] = constraintsDictionary["area"] ?? new StringRouteConstraint(areaName); constraintsDictionary["area"] = constraintsDictionary["area"] ?? new StringRouteConstraint(areaName);
routes.MapControllerRoute(name, template, defaultsDictionary, constraintsDictionary, dataTokens); routes.MapControllerRoute(name, pattern, defaultsDictionary, constraintsDictionary, dataTokens);
} }
/// <summary> /// <summary>
@ -175,7 +175,7 @@ namespace Microsoft.AspNetCore.Builder
/// <para> /// <para>
/// <see cref="MapFallbackToController(IEndpointRouteBuilder, string, string)"/> does not re-execute routing, and will /// <see cref="MapFallbackToController(IEndpointRouteBuilder, string, string)"/> does not re-execute routing, and will
/// not generate route values based on routes defined elsewhere. When using this overload, the <c>path</c> route value /// not generate route values based on routes defined elsewhere. When using this overload, the <c>path</c> route value
/// will be available. /// will be available.
/// </para> /// </para>
/// <para> /// <para>
/// <see cref="MapFallbackToController(IEndpointRouteBuilder, string, string)"/> does not attempt to disambiguate between /// <see cref="MapFallbackToController(IEndpointRouteBuilder, string, string)"/> does not attempt to disambiguate between
@ -184,8 +184,8 @@ namespace Microsoft.AspNetCore.Builder
/// </para> /// </para>
/// </remarks> /// </remarks>
public static void MapFallbackToController( public static void MapFallbackToController(
this IEndpointRouteBuilder routes, this IEndpointRouteBuilder routes,
string action, string action,
string controller) string controller)
{ {
if (routes == null) if (routes == null)
@ -209,7 +209,7 @@ namespace Microsoft.AspNetCore.Builder
GetOrCreateDataSource(routes); GetOrCreateDataSource(routes);
// Maps a fallback endpoint with an empty delegate. This is OK because // Maps a fallback endpoint with an empty delegate. This is OK because
// we don't expect the delegate to run. // we don't expect the delegate to run.
routes.MapFallback(context => Task.CompletedTask).Add(b => routes.MapFallback(context => Task.CompletedTask).Add(b =>
{ {
// MVC registers a policy that looks for this metadata. // MVC registers a policy that looks for this metadata.
@ -228,8 +228,8 @@ namespace Microsoft.AspNetCore.Builder
/// <param name="controller">The controller name.</param> /// <param name="controller">The controller name.</param>
/// <remarks> /// <remarks>
/// <para> /// <para>
/// <see cref="MapFallbackToController(IEndpointRouteBuilder, string, string, string)"/> is intended to handle cases /// <see cref="MapFallbackToController(IEndpointRouteBuilder, string, string, string)"/> is intended to handle cases
/// where URL path of the request does not contain a file name, and no other endpoint has matched. This is convenient /// where URL path of the request does not contain a file name, and no other endpoint has matched. This is convenient
/// for routing requests for dynamic content to a SPA framework, while also allowing requests for non-existent files to /// for routing requests for dynamic content to a SPA framework, while also allowing requests for non-existent files to
/// result in an HTTP 404. /// result in an HTTP 404.
/// </para> /// </para>
@ -242,8 +242,8 @@ namespace Microsoft.AspNetCore.Builder
/// </para> /// </para>
/// <para> /// <para>
/// <see cref="MapFallbackToController(IEndpointRouteBuilder, string, string, string)"/> does not re-execute routing, and will /// <see cref="MapFallbackToController(IEndpointRouteBuilder, string, string, string)"/> does not re-execute routing, and will
/// not generate route values based on routes defined elsewhere. When using this overload, the route values provided by matching /// not generate route values based on routes defined elsewhere. When using this overload, the route values provided by matching
/// <paramref name="pattern"/> will be available. /// <paramref name="pattern"/> will be available.
/// </para> /// </para>
/// <para> /// <para>
/// <see cref="MapFallbackToController(IEndpointRouteBuilder, string, string, string)"/> does not attempt to disambiguate between /// <see cref="MapFallbackToController(IEndpointRouteBuilder, string, string, string)"/> does not attempt to disambiguate between
@ -283,7 +283,7 @@ namespace Microsoft.AspNetCore.Builder
GetOrCreateDataSource(routes); GetOrCreateDataSource(routes);
// Maps a fallback endpoint with an empty delegate. This is OK because // Maps a fallback endpoint with an empty delegate. This is OK because
// we don't expect the delegate to run. // we don't expect the delegate to run.
routes.MapFallback(pattern, context => Task.CompletedTask).Add(b => routes.MapFallback(pattern, context => Task.CompletedTask).Add(b =>
{ {
// MVC registers a policy that looks for this metadata. // MVC registers a policy that looks for this metadata.
@ -314,7 +314,7 @@ namespace Microsoft.AspNetCore.Builder
/// <para> /// <para>
/// <see cref="MapFallbackToAreaController(IEndpointRouteBuilder, string, string, string)"/> does not re-execute routing, and will /// <see cref="MapFallbackToAreaController(IEndpointRouteBuilder, string, string, string)"/> does not re-execute routing, and will
/// not generate route values based on routes defined elsewhere. When using this overload, the <c>path</c> route value /// not generate route values based on routes defined elsewhere. When using this overload, the <c>path</c> route value
/// will be available. /// will be available.
/// </para> /// </para>
/// <para> /// <para>
/// <see cref="MapFallbackToAreaController(IEndpointRouteBuilder, string, string, string)"/> does not attempt to disambiguate between /// <see cref="MapFallbackToAreaController(IEndpointRouteBuilder, string, string, string)"/> does not attempt to disambiguate between
@ -349,7 +349,7 @@ namespace Microsoft.AspNetCore.Builder
GetOrCreateDataSource(routes); GetOrCreateDataSource(routes);
// Maps a fallback endpoint with an empty delegate. This is OK because // Maps a fallback endpoint with an empty delegate. This is OK because
// we don't expect the delegate to run. // we don't expect the delegate to run.
routes.MapFallback(context => Task.CompletedTask).Add(b => routes.MapFallback(context => Task.CompletedTask).Add(b =>
{ {
// MVC registers a policy that looks for this metadata. // MVC registers a policy that looks for this metadata.
@ -369,8 +369,8 @@ namespace Microsoft.AspNetCore.Builder
/// <param name="area">The area name.</param> /// <param name="area">The area name.</param>
/// <remarks> /// <remarks>
/// <para> /// <para>
/// <see cref="MapFallbackToAreaController(IEndpointRouteBuilder, string, string, string, string)"/> is intended to handle /// <see cref="MapFallbackToAreaController(IEndpointRouteBuilder, string, string, string, string)"/> is intended to handle
/// cases where URL path of the request does not contain a file name, and no other endpoint has matched. This is /// cases where URL path of the request does not contain a file name, and no other endpoint has matched. This is
/// convenient for routing requests for dynamic content to a SPA framework, while also allowing requests for non-existent files to /// convenient for routing requests for dynamic content to a SPA framework, while also allowing requests for non-existent files to
/// result in an HTTP 404. /// result in an HTTP 404.
/// </para> /// </para>
@ -383,7 +383,7 @@ namespace Microsoft.AspNetCore.Builder
/// </para> /// </para>
/// <para> /// <para>
/// <see cref="MapFallbackToAreaController(IEndpointRouteBuilder, string, string, string, string)"/> does not re-execute routing, and will /// <see cref="MapFallbackToAreaController(IEndpointRouteBuilder, string, string, string, string)"/> does not re-execute routing, and will
/// not generate route values based on routes defined elsewhere. When using this overload, the route values provided by matching /// not generate route values based on routes defined elsewhere. When using this overload, the route values provided by matching
/// <paramref name="pattern"/> will be available. /// <paramref name="pattern"/> will be available.
/// </para> /// </para>
/// <para> /// <para>
@ -425,7 +425,7 @@ namespace Microsoft.AspNetCore.Builder
GetOrCreateDataSource(routes); GetOrCreateDataSource(routes);
// Maps a fallback endpoint with an empty delegate. This is OK because // Maps a fallback endpoint with an empty delegate. This is OK because
// we don't expect the delegate to run. // we don't expect the delegate to run.
routes.MapFallback(pattern, context => Task.CompletedTask).Add(b => routes.MapFallback(pattern, context => Task.CompletedTask).Add(b =>
{ {
// MVC registers a policy that looks for this metadata. // MVC registers a policy that looks for this metadata.

View File

@ -59,7 +59,7 @@ namespace Microsoft.AspNetCore.Builder
/// <summary> /// <summary>
/// Adds a route to the <see cref="IRouteBuilder"/> with the given MVC area with the specified /// Adds a route to the <see cref="IRouteBuilder"/> with the given MVC area with the specified
/// <paramref name="name"/>, <paramref name="areaName"/>, <paramref name="template"/>, /// <paramref name="name"/>, <paramref name="areaName"/>, <paramref name="template"/>,
/// <paramref name="defaults"/>, and <paramref name="constraints"/>. /// <paramref name="defaults"/>, and <paramref name="constraints"/>.
/// </summary> /// </summary>
/// <param name="routeBuilder">The <see cref="IRouteBuilder"/> to add the route to.</param> /// <param name="routeBuilder">The <see cref="IRouteBuilder"/> to add the route to.</param>
@ -89,7 +89,7 @@ namespace Microsoft.AspNetCore.Builder
/// <summary> /// <summary>
/// Adds a route to the <see cref="IRouteBuilder"/> with the given MVC area with the specified /// Adds a route to the <see cref="IRouteBuilder"/> with the given MVC area with the specified
/// <paramref name="name"/>, <paramref name="areaName"/>, <paramref name="template"/>, /// <paramref name="name"/>, <paramref name="areaName"/>, <paramref name="template"/>,
/// <paramref name="defaults"/>, <paramref name="constraints"/>, and <paramref name="dataTokens"/>. /// <paramref name="defaults"/>, <paramref name="constraints"/>, and <paramref name="dataTokens"/>.
/// </summary> /// </summary>
/// <param name="routeBuilder">The <see cref="IRouteBuilder"/> to add the route to.</param> /// <param name="routeBuilder">The <see cref="IRouteBuilder"/> to add the route to.</param>

View File

@ -43,11 +43,11 @@ namespace MvcSandbox
builder.MapControllerRoute( builder.MapControllerRoute(
name: "default", name: "default",
template: "{controller=Home}/{action=Index}/{id?}"); pattern: "{controller=Home}/{action=Index}/{id?}");
builder.MapControllerRoute( builder.MapControllerRoute(
name: "transform", name: "transform",
template: "Transform/{controller:slugify=Home}/{action:slugify=Index}/{id?}", pattern: "Transform/{controller:slugify=Home}/{action:slugify=Index}/{id?}",
defaults: null, defaults: null,
constraints: new { controller = "Home" }); constraints: new { controller = "Home" });

View File

@ -29,8 +29,8 @@ namespace ApplicationModelWebSite
{ {
app.UseRouting(routes => app.UseRouting(routes =>
{ {
routes.MapControllerRoute(name: "areaRoute", template: "{area:exists}/{controller=Home}/{action=Index}"); routes.MapControllerRoute(name: "areaRoute", pattern: "{area:exists}/{controller=Home}/{action=Index}");
routes.MapControllerRoute(name: "default", template: "{controller}/{action}/{id?}"); routes.MapControllerRoute(name: "default", pattern: "{controller}/{action}/{id?}");
routes.MapRazorPages(); routes.MapRazorPages();
}); });

View File

@ -39,12 +39,12 @@ namespace BasicWebSite
{ {
routes.MapControllerRoute( routes.MapControllerRoute(
name: "ActionAsMethod", name: "ActionAsMethod",
template: "{controller}/{action}", pattern: "{controller}/{action}",
defaults: new { controller = "Home", action = "Index" }); defaults: new { controller = "Home", action = "Index" });
routes.MapControllerRoute( routes.MapControllerRoute(
name: "PageRoute", name: "PageRoute",
template: "{controller}/{action}/{page}"); pattern: "{controller}/{action}/{page}");
}); });
} }
} }

View File

@ -34,15 +34,15 @@ namespace HtmlGenerationWebSite
{ {
routes.MapControllerRoute( routes.MapControllerRoute(
name: "areaRoute", name: "areaRoute",
template: "{area:exists}/{controller}/{action}/{id?}", pattern: "{area:exists}/{controller}/{action}/{id?}",
defaults: new { action = "Index" }); defaults: new { action = "Index" });
routes.MapControllerRoute( routes.MapControllerRoute(
name: "productRoute", name: "productRoute",
template: "Product/{action}", pattern: "Product/{action}",
defaults: new { controller = "Product" }); defaults: new { controller = "Product" });
routes.MapControllerRoute( routes.MapControllerRoute(
name: "default", name: "default",
template: "{controller}/{action}/{id?}", pattern: "{controller}/{action}/{id?}",
defaults: new { controller = "HtmlGeneration_Home", action = "Index" }); defaults: new { controller = "HtmlGeneration_Home", action = "Index" });
routes.MapRazorPages(); routes.MapRazorPages();

View File

@ -161,7 +161,7 @@ namespace Company.WebApplication1
{ {
routes.MapControllerRoute( routes.MapControllerRoute(
name: "default", name: "default",
template: "{controller=Home}/{action=Index}/{id?}"); pattern: "{controller=Home}/{action=Index}/{id?}");
routes.MapRazorPages(); routes.MapRazorPages();
}); });

View File

@ -44,7 +44,7 @@ type Startup private () =
app.UseRouting(fun routes -> app.UseRouting(fun routes ->
routes.MapControllerRoute( routes.MapControllerRoute(
name = "default", name = "default",
template = "{controller=Home}/{action=Index}/{id?}") |> ignore pattern = "{controller=Home}/{action=Index}/{id?}") |> ignore
routes.MapRazorPages() |> ignore) |> ignore routes.MapRazorPages() |> ignore) |> ignore
app.UseAuthorization() |> ignore app.UseAuthorization() |> ignore