0

I need to keep aurhorized user in the Blazor Server app as long as it possible so I put folowing code in the Program.cs

builder.Services.ConfigureApplicationCookie(config =>
{
    config.Cookie.Name = ".MyApp.Session";
    config.SlidingExpiration = true;
    config.ExpireTimeSpan = TimeSpan.FromDays(360);
    config.Cookie.HttpOnly = true;
});

builder.Services.AddSession(options =>
{
    options.IdleTimeout = TimeSpan.FromDays(360);
    options.Cookie.IsEssential = true;
    options.Cookie.HttpOnly = true;
});

So I expect that after login the HTML inside <Authorized> tag will be visible as it described here.

<AuthorizeView>
    <Authorized>
        … Some HTML
    </Authorized>
</AuthorizeView>

But after 20 minutes everything inside <Authorized> tag is disappearing.

Anyway after I press F5 in the web browser it appears again and as I see that user is still logged on and authorized. Hmmm...

Please help me to keep UI of the authorized user visible. Thanks!

NoWar
  • 36,338
  • 80
  • 323
  • 498

2 Answers2

1

I'm assuming it happens when idle? SignalR default behaviour is that it disconnects after 30 min of idle time. This will cause UI to lose its state and to restore it, page needs to be refreshed. You can try this, but make sure to monitor server resources as more idle connections will be maintained this way.

builder.Services.AddServerSideBlazor();
builder.Services.Configure<HubOptions>(options =>
{
    options.KeepAliveInterval = TimeSpan.FromMinutes(5);
    options.ClientTimeoutInterval = TimeSpan.FromMinutes(10);
});
Varin
  • 2,354
  • 2
  • 20
  • 37
0

From Secure ASP.NET Core Blazor Server apps we can know

Blazor Server apps periodically revalidate the user's authentication state, currently every 30 minutes by default.

and from this we can see

For a Blazor Server app created from the Blazor Server project template with authentication enabled, the default 30 minute revalidation interval can be adjusted in RevalidatingIdentityAuthenticationStateProvider

the following line which you can edit:

protected override TimeSpan RevalidationInterval => TimeSpan.FromMinutes(30);

Besides, have a look at this link hope it help.

Qing Guo
  • 6,041
  • 1
  • 2
  • 10