Update Blazor templates to use TempData#65752
Conversation
There was a problem hiding this comment.
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
ITempDatavia cascading parameters and pass it into redirect helpers. - Adjust
RedirectToInvalidUserto take an explicitClaimsPrincipalplusITempData.
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. |
…iurina/aspnetcore into tempdata-templates-update
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
javiercn
left a comment
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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. |
|
Started backporting to |
|
@dariatiurina backporting to 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 |
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.StatusMessagecookie with a 5-secondMaxAge) with the built-in TempData mechanism, which is simpler and follows standard ASP.NET Core patterns.Changes
IdentityRedirectManager.csStatusCookieNameconstant,StatusCookieBuilder, and all cookie-writing logicStatusMessageKeyconstant ("Identity.StatusMessage") for the TempData entry keyRedirectToWithStatus,RedirectToCurrentPageWithStatus, andRedirectToInvalidUsermethods entirely — status message passing is now handled by the pages themselves via[SupplyParameterFromTempData]usingdirectives (Microsoft.AspNetCore.Identity,BlazorWebCSharp._1.Data)StatusMessage.razor[Parameter] string? MessageHttpContextcascading parameter, cookie reading logic,messageFromCookiefield, andDisplayMessagecomputed propertyInvalidUser.razorUserManager.GetUserId(HttpContext.User)instead of receiving it through a redirect fromIdentityRedirectManagerAccount pages (16
.razorfiles)[SupplyParameterFromTempData(Name = IdentityRedirectManager.StatusMessageKey)]property to each page for reading and writing status messages via TempDataIdentityStatusMessageduring initialization and stores it in a localmessagefield, then nulls it out (TempData is one-time-read)RedirectManager.RedirectToWithStatus(url, message, HttpContext)calls with settingIdentityStatusMessage = messagefollowed byRedirectManager.RedirectTo(url)RedirectManager.RedirectToInvalidUser(UserManager, HttpContext)calls withRedirectManager.RedirectTo("Account/InvalidUser")<StatusMessage />now pass the message explicitly:<StatusMessage Message="@message" />Minor fix
ExternalLogin.razor(<div class=→<div class=)ConfirmEmailChange.razorwhere the error message string was not interpolated ('{userId}'→'{UserId}')