ahmedaziz
Well-known member
- Joined
- Feb 22, 2023
- Messages
- 55
- Programming Experience
- 1-3
I working on blazor application server side . i face error when apply session timeout
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
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 .
bugs and error details:
Category: Microsoft.AspNetCore.Components.Server.Circuits.RemoteNavigationManager
EventId: 4
SpanId: 7336f0e333159b9e
TraceId: 1c34008822a09f63877a1646dd4c58c1
ParentId: 0000000000000000
RequestId: 80000121-0000-f300-b63f-84710c7967bb
RequestPath: /_blazor
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.<<NavigateToCore>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
session time out error task cancelled:
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
window.location.href = "/Login/Login"; // redirect to login page
} else {
setTimeout(function () { checkSessionTimeout(currentUrl); }, 1000); // check again in 1 second
}
checkSessionTimeout(window.location.href);
}
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 .