Skip to content

[Consumes] attribute does not accept wildcard media types #63901

@poveden

Description

@poveden

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

ConsumesAttribute constructors use GetContentTypes() to populate the ContentTypes property and to ensure that no wildcard media types are used:

https://github.com/dotnet/aspnetcore/blob/4f8086c41755f61ce2c5988f2f6ee0d305dbd0b8/src/Mvc/Mvc.Core/src/ConsumesAttribute.cs#L236C1-L256C6

This effectively forbids declarations like:

[Consumes("text/*")]
public IActionResult SomeAction() { ... }

However, the Accept() method uses IsSubsetOfAnyContentType() to check if a request's content type is a subtype of a media type in ContentTypes:

https://github.com/dotnet/aspnetcore/blob/4f8086c41755f61ce2c5988f2f6ee0d305dbd0b8/src/Mvc/Mvc.Core/src/ConsumesAttribute.cs#L128C1-L141C1

Expected Behavior

I believe that [Consumes] should allow wildcard media types, unless there's some side effect that I cannot see. Regardless of wheter [FromBody] is used or not, just the ability to filter on media subtypes is really useful.

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version

9.0.305

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templates

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions