Allow backwards-forwards navigation caching with antiforgery tokens
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 290
Description
### Is there an existing issue for this?
- [X] I have searched the existing issues
### Describe the bug
Currently, using the [default antiforgery](https://github.com/dotnet/aspnetcore/blob/b3b8dffff4d092058b2d8942268b498cbfdb14ec/src/Antiforgery/src/Internal/DefaultAntiforgery.cs#L373) implementation (`DefaultAntiforgery`) the headers `"no-cache, no-store"` are supplied.
The `no-store` header has the unfortunate side effect of slowing browser navigation by incurring additional web requests to the server whenever the user navigates using the forward and backward buttons.
From my (limited) understanding of antiforgery tokens, this should be entirely doable.
This results in a page diagnostics warning. The rest of the reasons for this error disappear without the debugger attached.

Disabling antiforgery site-wide is not simple nor does it appear to be officially supported.
### Expected Behavior
Antiforgery should use `no-cache` instead of `no-cache, no-store`; or at least make this configurable so that backward-forward caching can be easily enabled.
### Steps To Reproduce
1. Create a blank project
2. Disable dom preservation by replacing
```html
```
With
```html
Blazor.start({
ssr: { disableDomPreservation: true }
});
```
3. Add the time to the home page so we can see whether it's being cached
4. Launch the application.
5. Navigate from the home page to another page, and then navigate back to the home page using the back button.
6. Observe that the time has been updated, and in the network tab observe that a web request has been made.
You can check out the project here.\
https://github.com/Fydar/AntiforgeryNoCacheIssue
### Exceptions (if any)
_No response_
### .NET Version
8.0.200
### Anything else?
https://web.dev/articles/bfcache#minimize-no-store
Contributor guide
Assessment
This issue has not been assessed yet.