Skip to content

When the 'no-cache' Response Caching Header set, 'max-age' still required. #42705

@lc6464

Description

@lc6464

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

In ASP.NET Core Web API (MVC),I received An unhandled exception occurred while processing the request.

InvalidOperationException: If the 'NoStore' property is not set to true, 'Duration' property must be specified.
Microsoft.AspNetCore.Mvc.Filters.ResponseCacheFilterExecutor.Execute(FilterContext context)

I set the cacheProfile.Location ResponseCacheLocation.None, the Cache-Control response header should have been set to no-cache, but it threw an exception. If I set Duration = 0, the value of the response header will become no-cache,max-age=0, which doesn't seem reasonable.

Expected Behavior

When I set Location to None, it should not throw an exception, and set the value of the response header to no-cache without max-age.

Steps To Reproduce

  1. Clone https://github.com/lc6464/api.lcwebsite.cn.git
  2. Remove Duration = 0, in Program.cs:39
  3. Changed Private1m to NoCache in Controllers\GetIPController.cs:18.
  4. Build
  5. Visit http://localhost:5000/GetIP

Exceptions (if any)

An unhandled exception occurred while processing the request.
InvalidOperationException: If the 'NoStore' property is not set to true, 'Duration' property must be specified.
Microsoft.AspNetCore.Mvc.Filters.ResponseCacheFilterExecutor.Execute(FilterContext context)

.NET Version

6.0.302

Anything else?

ASP.NET Core 6.0
Visual Studio 2022 17.2.6
dotnet --info:

.NET SDK (反映任何 global.json):
 Version:   6.0.302
 Commit:    c857713418

运行时环境:
 OS Name:     Windows
 OS Version:  10.0.22621
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\6.0.302\

global.json file:
  Not found

Host:
  Version:      6.0.7
  Architecture: x64
  Commit:       0ec02c8c96

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions