page components doesn't update after oidc authentication in blazor web app server based

Zahra Ghadyani 20 Reputation points
2025-06-18T15:25:31.8166667+00:00

I have a blazor web app (server based) with page components defined parametrically as below:

@page "/System/{iSysnum:int?}"
@page "/System/{iSysnum:int?}"
@implements IDisposable
@rendermode InteractiveServer
@page "/System/{iSysnum:int?}"
...
@using Microsoft.AspNetCore.Authorization
@attribute [Authorize]

I have added authentication in program.cs as follows:

builder.Services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
    .AddMicrosoftIdentityWebApp(options =>
    {
        builder.Configuration.Bind("AzureAdB2C", options);
    });

After successful log in in the web app, the pages /system/1, /system/2, ... become available and I can navigate to any one (/system/n). But when I navigate to a different page (/system/m) , only the heading text is updated but presented data are still from previous system. The system data gets updated when refresh the browser, but it is not the desired behavior...

P.S. The web app did update data for each system when navigating between pages before implementing the B2C authorization.

Blazor Training
Blazor Training
Blazor: A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.Training: Instruction to develop new skills.
39 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 77,631 Reputation points Volunteer Moderator
    2025-06-18T22:28:09.7766667+00:00

    when your Blazor app uses Azure Ad to login, the Blazor app redirects to a razor page to authenticate. this unloads the Blazor app. After authentication the razor pages redirects back to the Blazor hosting page which reloads the app. no Blazor state is preserved automatically. There must be a coding error on your part.

    maybe your old code did redirects instead of Blazor navigation.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.