Skip to content

[release/11.0-preview4] Update Blazor templates to use TempData#66456

Merged
wtgodbe merged 1 commit intodotnet:release/11.0-preview4from
dariatiurina:backport/pr-65752-to-11.0-preview4
Apr 24, 2026
Merged

[release/11.0-preview4] Update Blazor templates to use TempData#66456
wtgodbe merged 1 commit intodotnet:release/11.0-preview4from
dariatiurina:backport/pr-65752-to-11.0-preview4

Conversation

@dariatiurina
Copy link
Copy Markdown
Contributor

@dariatiurina dariatiurina commented Apr 24, 2026

Backport of #65752 to release/11.0-preview4

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}')

Customer Impact

Templates update to simplify them and show best practices.

Regression?

  • Yes
  • No

[If yes, specify the version the behavior has regressed from]

Risk

  • High
  • Medium
  • Low

[Justify the selection above]

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

When servicing release/2.3

  • Make necessary changes in eng/PatchConfig.props

@dariatiurina dariatiurina self-assigned this Apr 24, 2026
Copilot AI review requested due to automatic review settings April 24, 2026 09:23
@dariatiurina dariatiurina added the area-blazor Includes: Blazor, Razor Components label Apr 24, 2026
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

Backports the Blazor Identity template change to pass status messages between pages via TempData ([SupplyParameterFromTempData]) instead of the custom short-lived cookie approach.

Changes:

  • Simplifies StatusMessage into a purely presentational component that only renders an explicitly provided message.
  • Removes cookie-based status message plumbing from IdentityRedirectManager and updates account/manage pages to read/write status via TempData.
  • Updates invalid-user handling to generate its own message on the InvalidUser page rather than via redirect helper methods.

Reviewed changes

Copilot reviewed 20 out of 20 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWebCSharp.1/Components/Account/Shared/StatusMessage.razor Removes cookie-reading logic; renders only the passed-in message.
src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWebCSharp.1/Components/Account/Pages/Manage/TwoFactorAuthentication.razor Reads/writes status messages via TempData and passes message to StatusMessage.
src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWebCSharp.1/Components/Account/Pages/Manage/SetPassword.razor Uses TempData for post-redirect status messaging.
src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWebCSharp.1/Components/Account/Pages/Manage/ResetAuthenticator.razor Uses TempData for post-redirect status messaging and passes message to StatusMessage.
src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWebCSharp.1/Components/Account/Pages/Manage/RenamePasskey.razor Writes TempData status messages before redirecting back to Passkeys.
src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWebCSharp.1/Components/Account/Pages/Manage/PersonalData.razor Reads TempData message and passes it to 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 for post-redirect status messaging and passes message to StatusMessage.
src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWebCSharp.1/Components/Account/Pages/Manage/GenerateRecoveryCodes.razor Reads TempData message during initialization.
src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWebCSharp.1/Components/Account/Pages/Manage/ExternalLogins.razor Uses TempData for post-redirect status messaging and passes message to StatusMessage.
src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWebCSharp.1/Components/Account/Pages/Manage/EnableAuthenticator.razor Uses TempData for post-redirect status messaging.
src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWebCSharp.1/Components/Account/Pages/Manage/Email.razor Reads TempData message during initialization.
src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWebCSharp.1/Components/Account/Pages/Manage/Disable2fa.razor Uses TempData to pass status message when redirecting to 2FA page.
src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWebCSharp.1/Components/Account/Pages/Manage/DeletePersonalData.razor Reads TempData message during initialization.
src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWebCSharp.1/Components/Account/Pages/Manage/ChangePassword.razor Uses TempData for post-redirect status messaging.
src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWebCSharp.1/Components/Account/Pages/Login.razor Reads TempData status message into the login page’s message display.
src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWebCSharp.1/Components/Account/Pages/InvalidUser.razor Generates the invalid-user error message locally and passes it to StatusMessage.
src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWebCSharp.1/Components/Account/Pages/ExternalLogin.razor Uses TempData for redirect status messages; includes minor markup whitespace fix.
src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWebCSharp.1/Components/Account/Pages/ConfirmEmailChange.razor Uses TempData for redirect status messages and fixes the user-not-found message.
src/ProjectTemplates/Web.ProjectTemplates/content/BlazorWeb-CSharp/BlazorWebCSharp.1/Components/Account/IdentityRedirectManager.cs Removes cookie-based status helpers; introduces StatusMessageKey constant for TempData usage.

@dariatiurina dariatiurina requested a review from ilonatommy April 24, 2026 09:34
@ilonatommy ilonatommy added this to the 11.0-preview4 milestone Apr 24, 2026
@wtgodbe wtgodbe merged commit 1fecf36 into dotnet:release/11.0-preview4 Apr 24, 2026
34 checks passed
@dotnet-policy-service dotnet-policy-service Bot modified the milestone: 11.0-preview4 Apr 24, 2026
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.

4 participants