ahmed salah

ahmed salah

  • 1.2k
  • 547
  • 62.9k

Task was cancelled error when apply session timeout error ?

May 1 2023 6:24 AM

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.<<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

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 .


Answers (2)