How to get all active session of the logged in user in .net core mvc

John Russel Punio 0 Reputation points
2023-09-28T00:58:48.76+00:00

I'm currently working on a .net 7 mvc project. How can I get all the active sessions of a logged in user in .net core mvc. This is my setup currently:

builder.Services.AddDistributedSqlServerCache(options =>
    {
        options.ConnectionString = config.Database.ConnectionString;
        options.SchemaName = "dbo";
        options.TableName = "TestCache";
        options.DefaultSlidingExpiration = TimeSpan.FromMinutes(240);
    });

builder.Services.AddSession(options =>
    {
        options.IdleTimeout = TimeSpan.FromMinutes(120);
        options.Cookie.HttpOnly = true;
        options.Cookie.IsEssential = true;
        options.Cookie.Name = $".{Host}.Session";
    });
ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,526 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 64,566 Reputation points
    2023-09-28T15:18:34.9466667+00:00

    If you can use ISessionState.Keys collection to count the active session, but default session manager does not track session to user.

    0 comments No comments

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.