Skip to content

[WebToolsE2E] After adding Blazor Identity to a Blazor Web App (non-auth, .NET 10.0 project), the User Register failed with an exception:"IdentityRedirectManager can only be used during static rendering." #64572

@v-reinawang

Description

@v-reinawang

REGRESSION INFO: Not repro on VS 17.14.21

INSTALL STEP

  1. Clean machine: Win11 x64 23H2 ENU
  2. Install VS 18.3 Insiders 1.2 from https://aka.ms/vs/18/insiders/vs_Enterprise.exe
    • Web workload
    • Check 8.0/9.0 runtime
    • Includes SDK 10.0.100

REPRO STEPS

  1. File > New > Project > Blazor Web App > .NET 10.0 > Server ~ Per page/component > create.

  2. Right click the project > Add > New Scaffolded Item > Identity > Blazor Identity

    • DbContext class: Click + for Data context class and keep the context name by default
    • Database provider: Select "SQL Server/SQLite"
    • Click Add
  3. After scaffolding completed

    • You may encounter BUG 2611149, which requires updating the Microsoft.Build.* package version.
    • Update "BlazorApp1ContextConnection" to "BlazorApp1Context"
  4. Open Tools > NuGet Package Manager > Package Manager Console and run the following code.

Add-Migration CreateIdentitySchema -context <Contextname>
Update-Database -context <Contextname>
  1. Run the project and register a new user

NOTE:

  1. There have been similar bugs before: #3609 and #3657
  2. This issue does not reproduce in 9.0/8.0 project

ACTUAL:
The user register failed with an exception
Image
Image

fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
      An unhandled exception has occurred while executing the request.
      System.InvalidOperationException: IdentityRedirectManager can only be used during static rendering.
         at BlazorApp8.Components.Account.IdentityRedirectManager.RedirectTo(String uri) in C:\Users\v-reinawang\source\repos\BlazorApp8\BlazorApp8\Components\Account\IdentityRedirectManager.cs:line 32
         at BlazorApp8.Components.Account.IdentityRedirectManager.RedirectTo(String uri, Dictionary`2 queryParameters) in C:\Users\v-reinawang\source\repos\BlazorApp8\BlazorApp8\Components\Account\IdentityRedirectManager.cs:line 40
         at BlazorApp8.Components.Account.Pages.Register.RegisterUser(EditContext editContext) in C:\Users\v-reinawang\source\repos\BlazorApp8\BlazorApp8\Components\Account\Pages\Register.razor:line 96
         at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
         at Microsoft.AspNetCore.Components.Forms.EditForm.HandleSubmitAsync()
         at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
         at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)
         at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle, ComponentState owningComponentState)
         at Microsoft.AspNetCore.Components.Endpoints.EndpointHtmlRenderer.<WaitForNonStreamingPendingTasks>g__Execute|58_0()
         at Microsoft.AspNetCore.Components.Endpoints.RazorComponentEndpointInvoker.RenderComponentCore(HttpContext context)
         at Microsoft.AspNetCore.Components.Endpoints.RazorComponentEndpointInvoker.RenderComponentCore(HttpContext context)
         at Microsoft.AspNetCore.Components.Rendering.RendererSynchronizationContext.<>c.<<InvokeAsync>b__10_0>d.MoveNext()
      --- End of stack trace from previous location ---
         at Microsoft.AspNetCore.Builder.ServerRazorComponentsEndpointConventionBuilderExtensions.<>c__DisplayClass1_1.<<AddInteractiveServerRenderMode>b__1>d.MoveNext()
      --- End of stack trace from previous location ---
         at Microsoft.AspNetCore.Antiforgery.Internal.AntiforgeryMiddleware.InvokeAwaited(HttpContext context)
         at Microsoft.AspNetCore.Diagnostics.StatusCodePagesMiddleware.Invoke(HttpContext context)
         at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
         at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
         at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddlewareImpl.Invoke(HttpContext context)

EXPECTED

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions