I working on blazor application server side . i face error when apply session timeout
Category: Microsoft.AspNetCore.Components.Server.Circuits.RemoteNavigationManager
EventId: 4
SpanId: 7336f0e333159b9e
TraceId: 1c34008822a09f63877a1646dd4c58c1
ParentId: 0000000000000000
RequestId: 80000121-0000-f300-b63f-84710c7967bb
TransportConnectionId: XIZLCkB1z0H-hsteYUeJJQ
Navigation failed when changing the location to /Dashboard/Meid
Exception:
System.Threading.Tasks.TaskCanceledException: A task was canceled.
at Microsoft.JSInterop.JSRuntime.InvokeAsync[TValue](Int64 targetInstanceId, String identifier, Object[] args)
at Microsoft.JSInterop.JSRuntimeExtensions.InvokeVoidAsync(IJSRuntime jsRuntime, String identifier, Object[] args)
at Microsoft.AspNetCore.Components.Server.Circuits.RemoteNavigationManager.<>c__DisplayClass13_0.<g__PerformNavigationAsync|0>d.MoveNext()
error happen on Dashboard page on InvokeAsync method on dashboard page but why this issue happen this is only my question
my code details Dashboard Page
protected override void OnInitialized()
{
DateTime now = DateTime.Now;
string nowString = now.ToString("yyyy-MM-ddTHH:mm:ss");
JS.InvokeVoidAsync("localStorage.setItem", "LastActivity",
now);
}
function checkSessionTimeout(currentUrl) {
var sessionTimeout = 20 * 60 * 1000; // 20 minutes in milliseconds
var lastActivity = new Date(Date.parse(localStorage.getItem("LastActivity"))); // get the last activity time from the client-side local storage
console.log("current date" + Date());
console.log("last date store" + lastActivity);
if (new Date() - lastActivity > sessionTimeout) {
localStorage.clear(); // clear the local storage
redirect to login page
} else {
setTimeout(function () { checkSessionTimeout(currentUrl); }, 1000); // check again in 1 second
}
}
this error happen on some remote pc but local pc this issue not happen
also when connect to server remote from my pc it not happen
some remote pc connected to this page happen this issue .
ahmed salahPosted May 2, 2023, 8:18 AM
I notice async remaining await are this reason of problem
Rajkiran SwainPosted May 2, 2023, 5:28 AM
The problem could be caused by a number of factors, but one possibility is that the task is taking too long to complete and is being cancelled due to a session timeout. The session timeout may be configured differently on different PCs, which could explain why the error occurs on some remote PCs but not on your local PC or when connected to the server remotely.
To troubleshoot the issue, you could try increasing the session timeout or modifying the code to perform the task more efficiently. Additionally, you could try logging more information about the task to determine why it might be taking too long to complete or getting cancelled.