Skip to content

Static files and file results don't ignore If-Modified-Since when If-None-Match is present (or If-Unmodified-Since when If-Match is present) #70770

Open

Description

@Manish-1kumar

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

MapStaticAssets, UseStaticFiles and Results.File/FileResult evaluate all four preconditions and take the "strongest" result. So when the date header disagrees with a matching ETag header, the date wins:

  • If-None-Match: <current etag> alone → 304. Adding an older If-Modified-Since → 200 with the full body.
  • If-Match: <current etag> alone → 200. Adding an older If-Unmodified-Since → 412.

RFC 9110 says a recipient MUST ignore If-Modified-Since when the request has If-None-Match (§13.1.3), and MUST ignore If-Unmodified-Since when it has If-Match (§13.1.4). The evaluation order in §13.2.2 says the same.

In practice, browsers send both validators. When a deployment updates file timestamps without changing their content, the ETag stays the same but Last-Modified moves forward. Every revalidation of those unchanged MapStaticAssets files then downloads the full body instead of getting 304. To reproduce: build and run an app with MapStaticAssets, request /site.css, then change only the file's timestamp, rebuild and run again. The ETag is unchanged ("Ep3l9apN…=") and Last-Modified moves from 07:05:18 to 17:58:16. A revalidation with the old If-None-Match and the old If-Modified-Since returns 200 with the full body, while If-None-Match alone returns 304.

Expected Behavior

When If-None-Match is present, If-Modified-Since is ignored, and when If-Match is present, If-Unmodified-Since is ignored.

Steps To Reproduce

The same app as in #70769, or any MapStaticAssets / UseStaticFiles / Results.File endpoint with an ETag and a Last-Modified:

Request headers UseStaticFiles MapStaticAssets TypedResults.File Expected
If-None-Match: <etag> 304 304 304 304
If-None-Match: <etag> + If-Modified-Since: Mon, 01 Jan 2024 00:00:00 GMT 200 200 200 304
If-Match: <etag> + If-Unmodified-Since: Mon, 01 Jan 2024 00:00:00 GMT 412 412 412 200

Exceptions (if any)

None.

.NET Version

10.0.401 SDK, Microsoft.AspNetCore.App 10.0.15

Anything else?

This looks intentional under RFC 2616: CacheHeaderTests.MissingEitherOrBothConditionsReturnsNormally (StaticFiles) and its copy in StaticAssetsIntegrationTests assert the current behavior (resp3: matching If-None-Match plus an older If-Modified-Since → 200), with a comment quoting RFC 2616 §13.3.4 ("MUST NOT return a response status of 304 (Not Modified) unless doing so is consistent with all of the conditional header fields in the request"). RFC 7232 and then RFC 9110 replaced that rule with the precedence above. The development handler in #70350 already ignores If-Modified-Since when If-None-Match is present.

The code is in GetMaxPreconditionState / GetPreconditionState in src/Shared/ResultsHelpers/FileResultHelper.cs, src/Middleware/StaticFiles/src/StaticFileContext.cs and src/StaticAssets/src/StaticAssetsInvoker.cs. A fix would skip the date state when the matching ETag header is present, in all three, and update those two tests.

Since this changes tested behavior, would you take a PR for it? If so, should it be one change for all three, or start with MapStaticAssets?

Activity

  1. added
    area-middleware
    on Nov 22, 2026
  2. github-actions commented on Nov 22, 2026

    @github-actions
    Contributor

    Triage Summary

    Area: area-middleware (UseStaticFiles / MapStaticAssets conditional request handling; also touches Results.File in src/Shared/ResultsHelpers)
    Type: Bug (reported behavior differs from the RFC 9110 precedence rules cited in the issue)

    Potential Duplicates

    Notes

    Generated by Issue Triage Agent for dotnet/aspnetcore for #70770 · copilot · auto · 23.8 AIC · ⌖ 1.02 AIC · ⊞ 7.6K · ◷

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-middleware

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions