admin管理员组文章数量:1406968
I'm developing a Blazor Server application with ASP.NET Core Identity and cookie-based authentication. I have implemented sliding expiration for the authentication cookie.
The challenge is to force an immediate redirection to an "inactive session" page when the session is invalidated. Inactivity, network issues, don't care.
If the server begins to clean up the session for any reason then attempt to redirect.
This is crucial to avoid situations where the user continues interacting with the app after their session has expired, only to experience errors or lost data when trying to submit forms or make server requests. this is usually related to inactivity but other situations may apply. Currently the app just locks up.
Redirecting on the next client server interaction is way to late. You can interact a lot with a Blazor app without having to make a round trip.
Specifically, I need the server to detect when the session has been invalidated (for any reason, not just inactivity) and automatically redirect the user to the /inactive-session
page before any interaction with the app takes place.
I'm developing a Blazor Server application with ASP.NET Core Identity and cookie-based authentication. I have implemented sliding expiration for the authentication cookie.
The challenge is to force an immediate redirection to an "inactive session" page when the session is invalidated. Inactivity, network issues, don't care.
If the server begins to clean up the session for any reason then attempt to redirect.
This is crucial to avoid situations where the user continues interacting with the app after their session has expired, only to experience errors or lost data when trying to submit forms or make server requests. this is usually related to inactivity but other situations may apply. Currently the app just locks up.
Redirecting on the next client server interaction is way to late. You can interact a lot with a Blazor app without having to make a round trip.
Specifically, I need the server to detect when the session has been invalidated (for any reason, not just inactivity) and automatically redirect the user to the /inactive-session
page before any interaction with the app takes place.
1 Answer
Reset to default 0To detect inactivity/idle you could follow this document https://learn.microsoft/en-us/aspnet/core/blazor/fundamentals/signalr?view=aspnetcore-9.0#monitor-server-side-circuit-activity.
Simply inject navigationmanager to perform redirect when idle.
private void CircuitIdle(object? sender, System.Timers.ElapsedEventArgs e)
{
logger.LogInformation("{CircuitId} is idle", currentCircuit?.Id);
_navigationManager.NavigateTo("/inactive-session");
}
You could set proper IdleTimeout instead of waiting for the websocket really disconnect (Server will not be able to perform client redirect because of the disconnect).
本文标签: aspnet coreDetecting session invalidationexpiration in NET 9 BlazorStack Overflow
版权声明:本文标题:asp.net core - Detecting session invalidationexpiration in .NET 9 Blazor - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744957699a2634456.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论