You can use database such as Redis to get all user sessions.
https://learn.microsoft.com/en-us/aspnet/core/performance/caching/distributed?view=aspnetcore-7.0
Redis is very simple to deploy.
1.Download from https://github.com/tporadowski/redis/releases "Redis-x64-5.0.14.1.zip" execute "redis-server.exe" Then you host a redis server at port 6379.
2.In Asp.net Core project, install package "windows.extensions.caching.stackexchangeredis." And register service. Sessions will automatically using redis with this simple configuration.
builder.Services.AddStackExchangeRedisCache(option =>
{
option.Configuration = "localhost";
});
3.Now you can use the following code to get all sessions in the redis server.
ConnectionMultiplexer multiplexer = ConnectionMultiplexer.Connect("localhost:6379,allowAdmin=True,connectTimeout=60000");
var AllSessions = multiplexer.GetServer("localhost:6379").Keys();
Console.WriteLine(string.Join(",", AllSessions));

It is same if you check sessions using redis destop manager

For Session_End there seems no samples to write a middleware.
https://github.com/dotnet/AspNetCore.Docs/issues/11869