dotnet / dotnet/aspnetcore

Cookie TempData fails on non-streaming SSR EditForm redirect with legacy navigation behavior

Open
#68,796 4 comments 0 reactions 1 assignee Claimed by @dariatiurina View on GitHub
area-blazor
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 5h
Merged PRs (30d)
276

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Describe the bug

Cookie-backed `[SupplyParameterFromTempData]` fails to persist a value during a non-streaming static SSR `EditForm` submission that redirects when the legacy navigation-exception behavior is enabled.

The server logs:

```text
warn: Microsoft.AspNetCore.Components.Endpoints.TempDataService[1]
TempData values written during or after streaming SSR cannot be persisted by the cookie TempData provider because the response has already started. Switch to the session-storage TempData provider (RazorComponentsServiceOptions.TempDataProviderType = TempDataProviderType.SessionStorage) to enable persistence in streaming SSR scenarios.
```

However, the app does not use `[StreamRendering]`, an interactive render mode, or session state. The POST returns `302 Found`, but no TempData cookie is written, so the redirected page does not receive the value.

This appears related to the persistence lifecycle change in #66832, but differs from #67021 because the failing component is not using streaming SSR.

Minimal repro: https://github.com/danroth27/TempDataRepro

### Expected Behavior

Cookie-backed TempData should persist the value across the POST-redirect-GET flow for a non-streaming static SSR form submission.

### Steps To Reproduce

1. Install .NET SDK `11.0.100-preview.7.26381.103`.
2. Clone https://github.com/danroth27/TempDataRepro.
3. Run `dotnet run`.
4. Open the displayed URL.
5. Select **Set TempData and redirect**.

The warning is logged and the redirected page does not display `TempData persisted.`

The project intentionally omits:

```xml
true
```

Adding that property prevents the failure. Apps created before this became the Preview 7 template default still use the affected legacy navigation-exception path.

### Exceptions (if any)

No exception reaches application code. The `Microsoft.AspNetCore.Components.Endpoints.TempDataService[1]` warning shown above is logged.

### .NET Version

`11.0.100-preview.7.26381.103`

### Anything else?

The repro is a static SSR-only Blazor Web App created with `dotnet new blazor -int None`. Its page uses `EditForm`, `[SupplyParameterFromTempData]`, and `NavigationManager.NavigateTo` for the redirect. Replacing `EditForm` with a plain form using `@onsubmit` and `forceLoad: true`, or enabling `BlazorDisableThrowNavigationException`, avoids the failure.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.