The Wayback Machine - https://web.archive.org/web/20210605041125/https://github.com/dotnet/aspnetcore/issues/33302
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ExceptionHandlerMiddleware does not clear IApiVersioningFeature #33302

Open
mattvperry opened this issue Jun 5, 2021 · 0 comments
Open

ExceptionHandlerMiddleware does not clear IApiVersioningFeature #33302

mattvperry opened this issue Jun 5, 2021 · 0 comments

Comments

@mattvperry
Copy link
Contributor

@mattvperry mattvperry commented Jun 5, 2021

var routeValuesFeature = context.Features.Get<IRouteValuesFeature>();
routeValuesFeature?.RouteValues?.Clear();

If someone is trying to use both the ApiVersioning feature and the ExceptionHandler configuration that uses a path name, you will get an ambiguous routing exception on every error because the router uses the selected routes in the IApiVersioningFeature from the original request which contains the original route.

Here is the routing code from ApiVersioning:
https://github.com/microsoft/aspnet-api-versioning/blob/e16b579d240574053ebd8e7ee38c8686beaee174/src/Microsoft.AspNetCore.Mvc.Versioning/Versioning/ApiVersionActionSelector.cs#L165

It seems like the ApiVersioning code lives in a separate repo not under the dotnet umbrella which introduces a dependency problem. I wonder if its possible to introduce an extension point for this middleware that allows implementers to add additional functionality to the ClearHttpContext step of the exception middleware. This way, the ApiVersioning folks could add an implementation which clears their feature.

Bottom line, the exception middleware is already clearing the IRouteValuesFeature in order to accomplish its goal because it is assuming that this is the only code that was involved in selecting the original route. However, any libraries which introduce a custom layer of routing, like ApiVersioning, will fail to be cleared properly before re-entering the pipeline. Adding some kind of extension point such that routing libraries can expose the means for others to clear their state, could clear this issue up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant