Home > other >  Change in behaviour for IActionInvokerProviders when using UseStatusCodePagesWithReExecute between c
Change in behaviour for IActionInvokerProviders when using UseStatusCodePagesWithReExecute between c

Time:12-19

Context:

Upgrading an existing aspnet application from core 3.1 to dotnet 6.0.

Issue: We have registered a IActionInvokerProvider in our web app. This simply adds some information to the context route data. We also use UseStatusCodePagesWithReExecute

app.UseStatusCodePagesWithReExecute("/somecontroller", "?statusCode={0}");

According to the documentation https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.mvc.abstractions.iactioninvoker?view=aspnetcore-3.1

An IActionInvoker is created for each request the MVC handles by querying the set of IActionInvokerProvider instances. See IActionInvokerProvider for more information.

When running this in netcoreapp3.1 when we return a NotFound() I can observe that 2 calls are made to our action provider OnProvidersExecuting. One for the request to the resource and one for a call expected UseStatusCodePagesWithReExecute to /somecontroller.

When targeting net6.0 and changing no other code this second call to /somecontroller does not get called only the first . If I call the endpoint /somecontroller?statusCode=404 I it does trigger the invoker. I cannot find a reference to a breaking change anywhere. perhaps I missed it.

Does anyone know what the casue might be?

I have tried altering the ordering of the pipeline.

Tried to repro it in https://github.com/csi-lund/core31tonet6issue In the version the Action provider never gets called at all

CodePudding user response:

The answer was a missed breaking change and documentation.

https://github.com/dotnet/aspnetcore/issues/45589

We skip the IActionInvoker by default as an optimization for controllers and pages. This is a really heavyweight way to add route data to the pipeline. You can set EnableActionInvokers to true to enable this behavior.

builder.Services.AddControllers(o => { o.EnableActionInvokers = true; }); In your sample it would be AddMvc (since you're using that).

No change in behaviour without documentation to indicate. (There might be might have missed it)

Yes, it seems like we missed this one. I'll make sure it gets documented.

PR: #27773 https://github.com/dotnet/aspnetcore/pull/27773

  • Related