From 96b77c866349a6d31508ce375ab98345a59604f1 Mon Sep 17 00:00:00 2001 From: Ryan Nowak Date: Mon, 27 Aug 2018 17:35:38 -0700 Subject: [PATCH] Fix aspnet/Routing#721 --- .../Internal/MvcEndpointDataSource.cs | 27 ++++++++++++------- .../ApplicationModelTest.cs | 2 +- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/Microsoft.AspNetCore.Mvc.Core/Internal/MvcEndpointDataSource.cs b/src/Microsoft.AspNetCore.Mvc.Core/Internal/MvcEndpointDataSource.cs index 560016a4c4..2d3f5e4ba2 100644 --- a/src/Microsoft.AspNetCore.Mvc.Core/Internal/MvcEndpointDataSource.cs +++ b/src/Microsoft.AspNetCore.Mvc.Core/Internal/MvcEndpointDataSource.cs @@ -174,7 +174,8 @@ namespace Microsoft.AspNetCore.Mvc.Internal endpointInfo.Defaults, ++conventionalRouteOrder, endpointInfo, - suppressLinkGeneration: false); + suppressLinkGeneration: false, + suppressPathMatching: false); endpoints.Add(subEndpoint); } @@ -213,7 +214,8 @@ namespace Microsoft.AspNetCore.Mvc.Internal endpointInfo.Defaults, ++conventionalRouteOrder, endpointInfo, - suppressLinkGeneration: false); + suppressLinkGeneration: false, + suppressPathMatching: false); endpoints.Add(endpoint); } } @@ -227,7 +229,8 @@ namespace Microsoft.AspNetCore.Mvc.Internal nonInlineDefaults: null, action.AttributeRouteInfo.Order, action.AttributeRouteInfo, - suppressLinkGeneration: action.AttributeRouteInfo.SuppressLinkGeneration); + suppressLinkGeneration: action.AttributeRouteInfo.SuppressLinkGeneration, + suppressPathMatching: action.AttributeRouteInfo.SuppressPathMatching); endpoints.Add(endpoint); } } @@ -375,7 +378,8 @@ namespace Microsoft.AspNetCore.Mvc.Internal object nonInlineDefaults, int order, object source, - bool suppressLinkGeneration) + bool suppressLinkGeneration, + bool suppressPathMatching) { RequestDelegate requestDelegate = (context) => { @@ -403,7 +407,8 @@ namespace Microsoft.AspNetCore.Mvc.Internal routeName, new RouteValueDictionary(action.RouteValues), source, - suppressLinkGeneration); + suppressLinkGeneration, + suppressPathMatching); var endpoint = new RouteEndpoint( requestDelegate, @@ -420,12 +425,11 @@ namespace Microsoft.AspNetCore.Mvc.Internal string routeName, RouteValueDictionary requiredValues, object source, - bool suppressLinkGeneration) + bool suppressLinkGeneration, + bool suppressPathMatching) { var metadata = new List { - // REVIEW: Used for debugging. Consider removing before release - source, action }; @@ -475,6 +479,11 @@ namespace Microsoft.AspNetCore.Mvc.Internal metadata.Add(new SuppressLinkGenerationMetadata()); } + if (suppressPathMatching) + { + metadata.Add(new SuppressMatchingMetadata()); + } + var metadataCollection = new EndpointMetadataCollection(metadata); return metadataCollection; } @@ -500,7 +509,5 @@ namespace Microsoft.AspNetCore.Mvc.Internal defaults[kvp.Key] = kvp.Value; } } - - private class SuppressLinkGenerationMetadata : ISuppressLinkGenerationMetadata { } } } \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Mvc.FunctionalTests/ApplicationModelTest.cs b/test/Microsoft.AspNetCore.Mvc.FunctionalTests/ApplicationModelTest.cs index dcb50e1d8e..a698af7ba4 100644 --- a/test/Microsoft.AspNetCore.Mvc.FunctionalTests/ApplicationModelTest.cs +++ b/test/Microsoft.AspNetCore.Mvc.FunctionalTests/ApplicationModelTest.cs @@ -128,7 +128,7 @@ namespace Microsoft.AspNetCore.Mvc.FunctionalTests Assert.Equal("From Header - HelloWorld", body); } - [Fact(Skip = "https://github.com/aspnet/Routing/issues/721")] + [Fact] public async Task ActionModelSuppressedForPathMatching_CannotBeRouted() { // Arrange & Act