Skip to content

Update Blazor templates to use TempData#65752

Merged
dariatiurina merged 11 commits intodotnet:mainfrom
dariatiurina:tempdata-templates-update
Apr 22, 2026
Merged

Update Blazor templates to use TempData#65752
dariatiurina merged 11 commits intodotnet:mainfrom
dariatiurina:tempdata-templates-update

Conversation

@dariatiurina
Copy link
Copy Markdown
Contributor

@dariatiurina dariatiurina commented Mar 12, 2026

Update Blazor templates to use TempData

Description

Updates the Blazor Identity project template to pass status messages between pages using [SupplyParameterFromTempData] instead of cookies. This replaces the custom cookie-based approach (Identity.StatusMessage cookie with a 5-second MaxAge) with the built-in TempData mechanism, which is simpler and follows standard ASP.NET Core patterns.

Changes

IdentityRedirectManager.cs

  • Removed the StatusCookieName constant, StatusCookieBuilder, and all cookie-writing logic
  • Added a StatusMessageKey constant ("Identity.StatusMessage") for the TempData entry key
  • Removed RedirectToWithStatus, RedirectToCurrentPageWithStatus, and RedirectToInvalidUser methods entirely — status message passing is now handled by the pages themselves via [SupplyParameterFromTempData]
  • Removed unused using directives (Microsoft.AspNetCore.Identity, BlazorWebCSharp._1.Data)

StatusMessage.razor

  • Simplified to a pure presentational component that accepts a [Parameter] string? Message
  • Removed the HttpContext cascading parameter, cookie reading logic, messageFromCookie field, and DisplayMessage computed property
  • The component no longer reads from cookies; it relies on the caller to pass the message explicitly

InvalidUser.razor

  • Now generates the error message locally using UserManager.GetUserId(HttpContext.User) instead of receiving it through a redirect from IdentityRedirectManager

Account pages (16 .razor files)

  • Added [SupplyParameterFromTempData(Name = IdentityRedirectManager.StatusMessageKey)] property to each page for reading and writing status messages via TempData
  • Each page reads IdentityStatusMessage during initialization and stores it in a local message field, then nulls it out (TempData is one-time-read)
  • Replaced RedirectManager.RedirectToWithStatus(url, message, HttpContext) calls with setting IdentityStatusMessage = message followed by RedirectManager.RedirectTo(url)
  • Replaced RedirectManager.RedirectToInvalidUser(UserManager, HttpContext) calls with RedirectManager.RedirectTo("Account/InvalidUser")
  • Pages that previously used parameterless <StatusMessage /> now pass the message explicitly: <StatusMessage Message="@message" />

Minor fix

  • Fixed a double-space typo in ExternalLogin.razor (<div class=<div class=)
  • Fixed a bug in ConfirmEmailChange.razor where the error message string was not interpolated ('{userId}''{UserId}')

@github-actions github-actions Bot added the area-blazor Includes: Blazor, Razor Components label Mar 12, 2026
@dariatiurina dariatiurina self-assigned this Mar 12, 2026
@ilonatommy ilonatommy added this to the .NET 11 Planning milestone Mar 13, 2026
@dariatiurina dariatiurina marked this pull request as ready for review March 13, 2026 15:45
Copilot AI review requested due to automatic review settings March 13, 2026 15:46
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the Blazor Identity template’s status-message flow to use ITempData instead of a short-lived custom cookie, aligning the template with the Razor Components TempData infrastructure.

Changes:

  • Replace cookie-based status message persistence with ITempData (IdentityRedirectManager + StatusMessage).
  • Update Identity account/manage pages to receive ITempData via cascading parameters and pass it into redirect helpers.
  • Adjust RedirectToInvalidUser to take an explicit ClaimsPrincipal plus ITempData.

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWebCSharp.1/Components/Account/IdentityRedirectManager.cs Switch redirect status storage from cookies to TempData and adjust redirect helper signatures.
src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWebCSharp.1/Components/Account/Shared/StatusMessage.razor Read status message from TempData instead of cookies.
src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWebCSharp.1/Components/Account/Pages/Manage/TwoFactorAuthentication.razor Add ITempData cascading parameter and pass it to redirect helpers.
src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWebCSharp.1/Components/Account/Pages/Manage/SetPassword.razor Add ITempData cascading parameter and pass it to redirect helpers.
src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWebCSharp.1/Components/Account/Pages/Manage/ResetAuthenticator.razor Add ITempData cascading parameter and pass it to redirect helpers.
src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWebCSharp.1/Components/Account/Pages/Manage/RenamePasskey.razor Add ITempData cascading parameter and pass it to redirect helpers.
src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWebCSharp.1/Components/Account/Pages/Manage/PersonalData.razor Add ITempData cascading parameter and pass it to redirect helpers.
src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWebCSharp.1/Components/Account/Pages/Manage/Passkeys.razor Add ITempData cascading parameter and pass it to redirect helpers (including updated error messaging).
src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWebCSharp.1/Components/Account/Pages/Manage/Index.razor Add ITempData cascading parameter and pass it to redirect helpers.
src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWebCSharp.1/Components/Account/Pages/Manage/GenerateRecoveryCodes.razor Add ITempData cascading parameter and pass it to redirect helpers.
src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWebCSharp.1/Components/Account/Pages/Manage/ExternalLogins.razor Add ITempData cascading parameter and pass it to redirect helpers.
src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWebCSharp.1/Components/Account/Pages/Manage/EnableAuthenticator.razor Add ITempData cascading parameter and pass it to redirect helpers.
src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWebCSharp.1/Components/Account/Pages/Manage/Email.razor Add ITempData cascading parameter and pass it to redirect helpers.
src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWebCSharp.1/Components/Account/Pages/Manage/Disable2fa.razor Add ITempData cascading parameter and pass it to redirect helpers.
src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWebCSharp.1/Components/Account/Pages/Manage/DeletePersonalData.razor Add ITempData cascading parameter and pass it to redirect helpers.
src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWebCSharp.1/Components/Account/Pages/Manage/ChangePassword.razor Add ITempData cascading parameter and pass it to redirect helpers.
src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWebCSharp.1/Components/Account/Pages/ExternalLogin.razor Add ITempData cascading parameter and pass it to redirect helpers.
src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWebCSharp.1/Components/Account/Pages/ConfirmEmailChange.razor Add ITempData cascading parameter and pass it to redirect helpers.

@dotnet-policy-service dotnet-policy-service Bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Mar 23, 2026
@ilonatommy ilonatommy removed the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Mar 23, 2026
@ilonatommy
Copy link
Copy Markdown
Member

/azp run

@azure-pipelines
Copy link
Copy Markdown

Azure Pipelines successfully started running 3 pipeline(s).

Copy link
Copy Markdown
Member

@javiercn javiercn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

But I expect that in its final form this uses SupplyParameterFromTempData and we completely get rid of IdentityRedirectManager.cs and just inline what we need on the callsites.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the Blazor Identity template status-message flow to use TempData-backed component parameters instead of a short-lived custom cookie, aligning the templates with built-in ASP.NET Core mechanisms for passing one-time messages across redirects.

Changes:

  • Removed the cookie-based status message implementation and replaced it with a TempData key (IdentityRedirectManager.StatusMessageKey).
  • Updated account/manage pages to read/write the status message via [SupplyParameterFromTempData], and pass the resolved value into <StatusMessage />.
  • Updated the InvalidUser page to render an error message directly (rather than relying on a redirect manager helper).

Reviewed changes

Copilot reviewed 20 out of 20 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWebCSharp.1/Components/Account/Shared/StatusMessage.razor Removes cookie fallback; component now only renders the provided Message.
src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWebCSharp.1/Components/Account/Pages/Manage/TwoFactorAuthentication.razor Reads/writes status message via TempData and passes it to StatusMessage.
src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWebCSharp.1/Components/Account/Pages/Manage/SetPassword.razor Uses TempData for post-redirect status message instead of redirect helper methods.
src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWebCSharp.1/Components/Account/Pages/Manage/ResetAuthenticator.razor Uses TempData to carry the “authenticator reset” success message across redirect.
src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWebCSharp.1/Components/Account/Pages/Manage/RenamePasskey.razor Uses TempData to send passkey rename outcomes back to the Passkeys page.
src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWebCSharp.1/Components/Account/Pages/Manage/PersonalData.razor Reads status message from TempData and displays it via StatusMessage.
src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWebCSharp.1/Components/Account/Pages/Manage/Passkeys.razor Converts multiple redirect-with-status flows to TempData + redirect.
src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWebCSharp.1/Components/Account/Pages/Manage/Index.razor Uses TempData to show “profile updated” and other outcomes after redirect.
src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWebCSharp.1/Components/Account/Pages/Manage/GenerateRecoveryCodes.razor Reads status from TempData for post-redirect display.
src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWebCSharp.1/Components/Account/Pages/Manage/ExternalLogins.razor Converts external-login add/remove status messaging to TempData.
src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWebCSharp.1/Components/Account/Pages/Manage/EnableAuthenticator.razor Uses TempData for setup/verification outcomes that redirect to other pages.
src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWebCSharp.1/Components/Account/Pages/Manage/Email.razor Reads status from TempData and displays it via StatusMessage.
src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWebCSharp.1/Components/Account/Pages/Manage/Disable2fa.razor Uses TempData to carry “2FA disabled” message across redirect.
src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWebCSharp.1/Components/Account/Pages/Manage/DeletePersonalData.razor Reads status from TempData and displays it via StatusMessage.
src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWebCSharp.1/Components/Account/Pages/Manage/ChangePassword.razor Uses TempData to carry success/failure messages across redirect.
src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWebCSharp.1/Components/Account/Pages/Login.razor Reads TempData status into the login error/status display.
src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWebCSharp.1/Components/Account/Pages/InvalidUser.razor Displays the invalid-user error through StatusMessage with a computed message.
src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWebCSharp.1/Components/Account/Pages/ExternalLogin.razor Converts external-login redirect errors to TempData + redirect; minor markup cleanup.
src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWebCSharp.1/Components/Account/Pages/ConfirmEmailChange.razor Uses TempData for invalid-link redirect messaging; fixes an interpolated message.
src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWebCSharp.1/Components/Account/IdentityRedirectManager.cs Removes cookie/status redirect helpers and introduces the TempData key constant.

@dariatiurina dariatiurina removed the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Apr 22, 2026
@dariatiurina dariatiurina merged commit 1daad8e into dotnet:main Apr 22, 2026
25 checks passed
@wtgodbe wtgodbe modified the milestones: 11.0-preview4, 11.0-preview5 Apr 24, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Started backporting to release/11.0-preview4 (link to workflow run)

@github-actions
Copy link
Copy Markdown
Contributor

@dariatiurina backporting to release/11.0-preview4 failed, the patch most likely resulted in conflicts. Please backport manually!

git am output
$ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch

Applying: Fixed bug with the lazy loading
Using index info to reconstruct a base tree...
M	src/Components/Endpoints/src/TempData/TempData.cs
M	src/Components/Endpoints/test/TempData/TempDataTest.cs
M	src/Components/test/testassets/Components.TestServer/RazorComponents/Pages/TempData/TempDataComponent.razor
Falling back to patching base and 3-way merge...
Auto-merging src/Components/Endpoints/test/TempData/TempDataTest.cs
CONFLICT (content): Merge conflict in src/Components/Endpoints/test/TempData/TempDataTest.cs
Auto-merging src/Components/test/testassets/Components.TestServer/RazorComponents/Pages/TempData/TempDataComponent.razor
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0001 Fixed bug with the lazy loading
Error: The process '/usr/bin/git' failed with exit code 128

Link to workflow output

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

Labels

area-blazor Includes: Blazor, Razor Components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants