Open alienwareone opened 1 year ago
Thank you for submitting this for API review. This will be reviewed by @dotnet/aspnet-api-review at the next meeting of the ASP.NET Core API Review group. Please ensure you take a look at the API review process documentation and ensure that:
@alienwareone I don't think you need to define a complicated SkipStatusCodePagesForApiControllers
method that adds filters or anything like that. Doesn't the following already work?
app.MapControllers().WithMetadata(new SkipStatusCodePagesAttribute());
It looks like the middleware is already checking for the ISkipStatusCodePagesMetadata
interface implemented by the attribute.
You just have to be careful to call UseStatusCodePages
after UseRouting
. This is probably a good reason to make writing an analyzer to flag this misordering a higher priority. We already have #38591 tracking this.
What do we think about adding a new IEndpointConventionBuilder
extension method that did exactly this called .SkipStatusCodePages()
instead? It's similar to your alternate proposal, but it should just work for everything including minimal route handlers and route groups.
You just have to be careful to call
UseStatusCodePages
afterUseRouting
. This is probably a good reason to make writing an analyzer to flag this misordering a higher priority. We already have #38591 tracking this.
@halter73 Thanks for pointing that out! With the correct ordering the need to add a filter is not required.
app.MapControllers().WithMetadata(new SkipStatusCodePagesAttribute());
But this will also skip the StatusCodePagesMiddleware for MVC Controllers which is not desired.
Thanks for contacting us.
We're moving this issue to the .NET 8 Planning
milestone for future evaluation / consideration. We would like to keep this around to collect more feedback, which can help us with prioritizing this work. We will re-evaluate this issue, during our next planning meeting(s).
If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues.
To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.
API Review Notes:
UseStatusCodePages
simply doesn't work for API controllers without an opt-in?ApiBehaviorOptions
, but it does align with the attribute name..MapControllers().WithMetadata(new SkipStatusCodePagesAttribute())
works to skip status code pages for all controllers, this will be specific to API Controllers.namespace Microsoft.AspNetCore.Mvc;
public class ApiBehaviorOptions : IEnumerable<ICompatibilitySwitch>
{
+ public bool SkipStatusCodePages { get; set; }
}
API Approved as proposed!
I'm working on it.
Background and Motivation
When mixing MVC Controllers with Api Controllers in an application, there should be a global setting in ApiBehaviorOptions to turn off the IStatusCodePagesFeature for Api Controllers to avoid overriding the raw api response with an MVC view/html based status code page implementation.
Proposed API
Usage Examples
Alternative Designs
Risks
There are no risks because the default value for
ApiBehaviorOptions.SkipStatusCodePages
will befalse
which is the current behavior.