Hello @Anonymous ,
I believe you have asked the same query on Stackoverflow it seems. Incidentally I was also searching for similar question and I stumbled on the question here.
Disclaimer :- The following answer is provided for the benefit of the QnA community and was originally written by Brando Zhang on Stackoverflow.
If you want to get a session id in your application, you could refer to below codes:
Firstly, you should register the session in the startup.cs ConfigureServices method.
services.AddSession(options =>
{
options.IdleTimeout = TimeSpan.FromSeconds(10);
options.Cookie.HttpOnly = true;
options.Cookie.IsEssential = true;
});
and add usesession method in the Configure method:
app.UseSession();
Secondly, you could get the session id in controller:
var re = HttpContext.Session.Id;
Notice: If you don't set any session in your controller, the sessionid will change for every request which sent from client side.
For detailed discussion around this . Please visit the original query on stackoverflow.
.