Session Expire

Folk,

Blazor server side

I need the system to log users out after say 30mins of no activity. Does anyone know how i can make this happen?

Thanks

John

Hi @johnmu,

You can try this StackOverflow answer. You will need to create a partial class for your Startup as described in the Custom Startup section of our article.

Atanas,

I have tried this

public partial class Startup
{
    partial void OnConfigureServices(IServiceCollection services)
    {
        services.ConfigureApplicationCookie(options =>
        {
            options.ExpireTimeSpan = TimeSpan.FromMinutes(1);
        });
    }



}

}

the OnConfigure method won't compile, probably because i don't know what directive to add.

Any thoughts?

thanks John

What are the compilation errors? Usually some namespace is not imported.

this is what happens when i copy the OnConfigure method intot the class

Indeed the actual signature of the method should be

partial void OnConfigure(IApplicationBuilder app, IWebHostEnvironment env)
{
}

I will update the documentation.

Hi,
I’m trying to do the same thing for .Net8 and .Net10 but got error on OnConfigureServices
Program.Custom.cs(8,22): error CS0759: No defining declaration found for implementing declaration of partial method 'Program.OnConfigureServices(IServiceCollection)'
Please help. Thanks.

Hi @Hoang,

You need to do that in Program.cs itself:

builder.Services.ConfigureApplicationCookie(options =>
{
    options.ExpireTimeSpan = new TimeSpan(8, 0, 0);
});

Thanks @korchev for your quick reply.