Skip to content

Commit 8a0d825

Browse files
committed
Revert "Re-run routing for implicit middlewares that require endpoints (#49732)"
This reverts commit e231c61.
1 parent a0c7939 commit 8a0d825

File tree

8 files changed

+9
-431
lines changed

8 files changed

+9
-431
lines changed

src/Antiforgery/src/AntiforgeryApplicationBuilderExtensions.cs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
using Microsoft.AspNetCore.Antiforgery;
55
using Microsoft.AspNetCore.Antiforgery.Internal;
6-
using Microsoft.AspNetCore.Routing;
7-
using Microsoft.Extensions.DependencyInjection;
86

97
namespace Microsoft.AspNetCore.Builder;
108

@@ -26,19 +24,6 @@ public static IApplicationBuilder UseAntiforgery(this IApplicationBuilder builde
2624
builder.VerifyAntiforgeryServicesAreRegistered();
2725

2826
builder.Properties[AntiforgeryMiddlewareSetKey] = true;
29-
30-
// The anti-forgery middleware adds annotations to HttpContext.Items to indicate that it has run
31-
// that will be validated by the EndpointsRoutingMiddleware later. To do this, we need to ensure
32-
// that routing has run and set the endpoint feature on the HttpContext associated with the request.
33-
if (builder.Properties.TryGetValue(RerouteHelper.GlobalRouteBuilderKey, out var routeBuilder) && routeBuilder is not null)
34-
{
35-
return builder.Use(next =>
36-
{
37-
var newNext = RerouteHelper.Reroute(builder, routeBuilder, next);
38-
var antiforgery = builder.ApplicationServices.GetRequiredService<IAntiforgery>();
39-
return new AntiforgeryMiddleware(antiforgery, newNext).Invoke;
40-
});
41-
}
4227
builder.UseMiddleware<AntiforgeryMiddleware>();
4328

4429
return builder;

src/Antiforgery/src/Microsoft.AspNetCore.Antiforgery.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
</ItemGroup>
2626

2727
<ItemGroup>
28-
<Compile Include="$(SharedSourceRoot)HttpExtensions.cs" LinkBase="Shared"/>
29-
<Compile Include="$(SharedSourceRoot)Reroute.cs" LinkBase="Shared"/>
28+
<Compile Include="$(SharedSourceRoot)HttpMethodExtensions.cs" LinkBase="Shared"/>
3029
</ItemGroup>
3130
</Project>

src/DefaultBuilder/test/Microsoft.AspNetCore.Tests/WebApplicationTests.cs

Lines changed: 3 additions & 373 deletions
Large diffs are not rendered by default.

src/Http/Http.Extensions/src/RequestDelegateFactory.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2101,9 +2101,6 @@ private static Expression BindComplexParameterFromFormItem(
21012101
ArrayPoolSharedReturnMethod,
21022102
formBuffer,
21032103
Expression.Constant(false));
2104-
var conditionalReturnBufferExpr = Expression.IfThen(
2105-
Expression.NotEqual(formBuffer, Expression.Constant(null)),
2106-
returnBufferExpr);
21072104

21082105
var parameterTypeNameConstant = Expression.Constant(TypeNameHelper.GetTypeDisplayName(parameter.ParameterType, fullName: false));
21092106
var parameterNameConstant = Expression.Constant(parameter.Name);
@@ -2136,6 +2133,7 @@ private static Expression BindComplexParameterFromFormItem(
21362133
initializeReaderExpr,
21372134
setMaxRecursionDepthExpr,
21382135
Expression.Assign(formArgument, invokeMapMethodExpr)),
2136+
<<<<<<< HEAD
21392137
conditionalReturnBufferExpr,
21402138
Expression.Catch(formDataMappingException, Expression.Block(
21412139
typeof(void),
@@ -2148,6 +2146,10 @@ private static Expression BindComplexParameterFromFormItem(
21482146
formDataMappingException,
21492147
Expression.Constant(factoryContext.ThrowOnBadRequest))
21502148
)))
2149+
=======
2150+
returnBufferExpr),
2151+
formArgument
2152+
>>>>>>> parent of e231c61c3a (Re-run routing for implicit middlewares that require endpoints (#49732))
21512153
);
21522154

21532155
factoryContext.ParamCheckExpressions.Add(bindAndCheckForm);

src/Security/Authentication/Core/src/AuthAppBuilderExtensions.cs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using Microsoft.AspNetCore.Authentication;
5-
using Microsoft.Extensions.DependencyInjection;
6-
using Microsoft.AspNetCore.Routing;
75

86
namespace Microsoft.AspNetCore.Builder;
97

@@ -24,20 +22,6 @@ public static IApplicationBuilder UseAuthentication(this IApplicationBuilder app
2422
ArgumentNullException.ThrowIfNull(app);
2523

2624
app.Properties[AuthenticationMiddlewareSetKey] = true;
27-
28-
// The authentication middleware adds annotation to HttpContext.Items to indicate that it has run
29-
// that will be validated by the EndpointsRoutingMiddleware later. To do this, we need to ensure
30-
// that routing has run and set the endpoint feature on the HttpContext associated with the request.
31-
if (app.Properties.TryGetValue(RerouteHelper.GlobalRouteBuilderKey, out var routeBuilder) && routeBuilder is not null)
32-
{
33-
return app.Use(next =>
34-
{
35-
var newNext = RerouteHelper.Reroute(app, routeBuilder, next);
36-
var authenticationSchemeProvider = app.ApplicationServices.GetRequiredService<IAuthenticationSchemeProvider>();
37-
return new AuthenticationMiddleware(newNext, authenticationSchemeProvider).Invoke;
38-
});
39-
}
40-
4125
return app.UseMiddleware<AuthenticationMiddleware>();
4226
}
4327
}

src/Security/Authentication/Core/src/Microsoft.AspNetCore.Authentication.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
<ItemGroup>
1414
<Compile Include="$(SharedSourceRoot)SecurityHelper\**\*.cs" />
15-
<Compile Include="$(SharedSourceRoot)Reroute.cs" />
1615
</ItemGroup>
1716

1817
<ItemGroup>

src/Security/Authorization/Policy/src/AuthorizationAppBuilderExtensions.cs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33

44
using Microsoft.AspNetCore.Authorization;
55
using Microsoft.AspNetCore.Authorization.Policy;
6-
using Microsoft.AspNetCore.Routing;
76
using Microsoft.Extensions.DependencyInjection;
8-
using Microsoft.Extensions.Logging;
97

108
namespace Microsoft.AspNetCore.Builder;
119

@@ -32,24 +30,6 @@ public static IApplicationBuilder UseAuthorization(this IApplicationBuilder app)
3230
VerifyServicesRegistered(app);
3331

3432
app.Properties[AuthorizationMiddlewareSetKey] = true;
35-
36-
// The authorization middleware adds annotation to HttpContext.Items to indicate that it has run
37-
// that will be validated by the EndpointsRoutingMiddleware later. To do this, we need to ensure
38-
// that routing has run and set the endpoint feature on the HttpContext associated with the request.
39-
if (app.Properties.TryGetValue(RerouteHelper.GlobalRouteBuilderKey, out var routeBuilder) && routeBuilder is not null)
40-
{
41-
return app.Use(next =>
42-
{
43-
var newNext = RerouteHelper.Reroute(app, routeBuilder, next);
44-
var authorizationPolicyProvider = app.ApplicationServices.GetRequiredService<IAuthorizationPolicyProvider>();
45-
var logger = app.ApplicationServices.GetRequiredService<ILogger<AuthorizationMiddleware>>();
46-
return new AuthorizationMiddlewareInternal(newNext,
47-
app.ApplicationServices,
48-
authorizationPolicyProvider,
49-
logger).Invoke;
50-
});
51-
}
52-
5333
return app.UseMiddleware<AuthorizationMiddlewareInternal>();
5434
}
5535

src/Security/Authorization/Policy/src/Microsoft.AspNetCore.Authorization.Policy.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
<ItemGroup>
1414
<Compile Include="$(SharedSourceRoot)SecurityHelper\**\*.cs" />
1515
<Compile Include="..\..\..\..\Http\Routing\src\DataSourceDependentCache.cs" Link="DataSourceDependentCache.cs" />
16-
<Compile Include="$(SharedSourceRoot)Reroute.cs" />
1716
</ItemGroup>
1817

1918
<ItemGroup>

0 commit comments

Comments
 (0)