Aperto Chiuso

In our Blazor server application, about the termination of the user's session if he does not perform any operations for a certain period of time #5740


User avatar
0
SevdeDuran creato

In our Blazor server application, we want the user's session to end if he or she does not perform any operations for a certain period of time. For this, I wrote the following codes in the program.cs file, but it did not work. While the user's password can be changed within a certain period of time in the interface, I could not find a setting related to this. How do we do it?

Here is my codes:

builder.Services.AddAuthentication(options => { options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme; })
.AddCookie(options =>
 { 
      options.ExpireTimeSpan = TimeSpan.FromMinutes(10); 
      options.SlidingExpiration = true; 
});

35 risposte
  • User Avatar
    0
    SevdeDuran creato

    Hi,
    When I click on the other menu after 3 minutes, the logs;

    2023-09-12 17:38:06.446 +03:00 [DBG] Added 0 entity changes to the current audit log 2023-09-12 17:38:06.455 +03:00 [INF] Executing ObjectResult, writing value of type 'Volo.Abp.Content.RemoteStreamContent'. 2023-09-12 17:38:06.459 +03:00 [INF] Executed action Volo.Abp.Account.AccountController.GetProfilePictureFileAsync (Volo.Abp.Account.Pro.Public.HttpApi) in 76.3419ms 2023-09-12 17:38:06.459 +03:00 [INF] Executed endpoint 'Volo.Abp.Account.AccountController.GetProfilePictureFileAsync (Volo.Abp.Account.Pro.Public.HttpApi)' 2023-09-12 17:38:06.462 +03:00 [INF] Request finished HTTP/2 GET https://localhost:44329/api/account/profile-picture-file/3a0b59c5-6aac-0e69-ed96-002240642456 - - - 200 1370 image/jpeg 118.7899ms 2023-09-12 17:38:25.054 +03:00 [DBG] Batch acquisition of 0 triggers 2023-09-12 17:38:52.866 +03:00 [DBG] Batch acquisition of 0 triggers 2023-09-12 17:39:16.410 +03:00 [DBG] Batch acquisition of 0 triggers 2023-09-12 17:39:43.014 +03:00 [DBG] Batch acquisition of 0 triggers 2023-09-12 17:40:07.666 +03:00 [DBG] Batch acquisition of 0 triggers

  • User Avatar
    0
    maliming creato
    Team di supporto Fullstack Developer

    Can you share your project?

    or you can test the code in a new project and share it.

    liming.ma@volosoft.com

  • User Avatar
    0
    maliming creato
    Team di supporto Fullstack Developer

    hi

    Where is the ConfigureApplicationCookie code?

    Can you share a template project with ConfigureApplicationCookie code?

  • User Avatar
    0
    SevdeDuran creato

    Hi,

    I'm sharing now.

  • User Avatar
    0
    maliming creato
    Team di supporto Fullstack Developer

    Just a moment, I'll confirm it again.

  • User Avatar
    0
    maliming creato
    Team di supporto Fullstack Developer

    hi

    context.Services.ConfigureApplicationCookie(options =>
    {
        options.ExpireTimeSpan = TimeSpan.FromSeconds(10);
        options.SlidingExpiration = true;
        options.Events.OnSigningIn = cookie =>
        {
            cookie.Properties.IsPersistent = true;
            return Task.CompletedTask;
        };
    });
    
    Configure<AbpEndpointRouterOptions>(options =>
    {
        options.EndpointConfigureActions.RemoveAll(x => x.Target.GetType().FullName.Contains("AbpAspNetCoreComponentsServerModule"));
        options.EndpointConfigureActions.Add(endpointContext =>
        {
            endpointContext.Endpoints.MapBlazorHub(httpConnectionDispatcherOptions => httpConnectionDispatcherOptions.CloseOnAuthenticationExpiration = true);
            endpointContext.Endpoints.MapFallbackToPage("/_Host");
        });
    });
    
  • User Avatar
    0
    SevdeDuran creato

    Hi,

    Thank you so much you are amazing :)

    When I click on another menu, it logs out after 10 seconds or when I don't click on anything. Could you share the sample project I sent you with the latest edit you made?

  • User Avatar
    0
    maliming creato
    Team di supporto Fullstack Developer

    hi

    These are the changes: https://support.abp.io/QA/Questions/5740#answer-3a0da383-face-7d11-aa37-6152b014966e

  • User Avatar
    0
    SevdeDuran creato

    Hi,

    Thanks. :)

  • User Avatar
    0
    maliming creato
    Team di supporto Fullstack Developer

    : )

Made with ❤️ on ABP v8.2.0-preview Updated on marzo 25, 2024, 15:11