How to smartly detect Inactive user session in Blazor app and perform session timeout?

Piyush Meshram 20 Reputation points
2024-01-18T10:38:15.8333333+00:00

I am working with the Blazor Web Assembly Project with Individual user account (Identity server) based login/ logout. I have not configured a custom token it's just a basic Blazor app with individual accounts.

So, the project default structure was created like this:-

Blazor Client, Blazor Server, Blazor Shared

How to achieve session timeout of the user and make it configurable. For example, if the default timeout is 1 minute then the admin user should be able to set it to 2 minutes or any other preferred timeout.

Requirements:

  1. If the user does not perform any action on the page then the session timeout. (This may include mouse scroll or any event.)

OR

  1. If the user does not perform any server call then only timeout.
Developer technologies | ASP.NET | ASP.NET Core
Developer technologies | .NET | Blazor
0 comments No comments
{count} votes

Accepted answer
  1. Bruce (SqlWork.com) 77,686 Reputation points Volunteer Moderator
    2024-01-18T17:21:04.6+00:00

    the easiest is to write a simple js routine that uses a timer, and hooks to all dom events you are interested in reseting the timer. if the time fires without an event, call the blazor code.

    you can detect httpclient calls in javascript two ways:

    • overide XMLHttpRequest.prototype.send
    • use a service worker.

0 additional answers

Sort by: Most helpful

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.