Skip to content

.NET Core 7 Output Cache does not work with app.UseEndpoints() properly #44739

@Gebov

Description

@Gebov

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

When configuring the endpoints using app.Map everything works as expected. But when the endpoints belong to a controller that is configured with app.UseEndpoints() the cache does not ignore one of the paths to the controller.

I am using a call to UseEndpoints to configure a controller with two methods, both of which have the OutputCache attribute set to a preconfigured policy based on a dynamic condition (in this case it just checks the URL. My real case scenario is somewhat different and checks for a flag in the HttpContext.Items collection).

Here are the tested URLS (test app is attached):

// expected to be cached, works, uses app.Map
/TimeCached

// expected to be not cached, works, uses app.Map
/TimeNotCached

// expected to be cached, works, uses app.UseEndpoints()
/Home/TimeCached

// expected not to be cached, does not work , uses app.UseEndpoints()
/Home/TimeNotCached

Expected Behavior

I would expect that the call to app.UseEndpoints() would behave the same way as app.Map() and respectively cache and not cache depending on a dynamic condition within the configured policy.

Steps To Reproduce

Just run the code sample and browse the following URLS:

// expected to be cached, works, uses app.Map
/TimeCached

// expected to be not cached, works, uses app.Map
/TimeNotCached

// expected to be cached, works, uses app.UseEndpoints()
/Home/TimeCached

// expected not to be cached, does not work , uses app.UseEndpoints()
/Home/TimeNotCached

Exceptions (if any)

No response

.NET Version

7.0.100-rc.2.22477.23

Anything else?

output-cache-tests.zip

Metadata

Metadata

Assignees

Labels

Needs: Attention 👋This issue needs the attention of a contributor, typically because the OP has provided an update.area-middlewareIncludes: URL rewrite, redirect, response cache/compression, session, and other general middlewaresfeature-output-caching

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions