Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get SessionID and UserHostAddress in .Net Core

In normal asp.net, we can get the value of this by giving:

UserSessionID = System.Web.HttpContext.Current.Session.SessionID;
IPAddress = System.Web.HttpContext.Current.Request.UserHostAddress;

How can we get the same in .Net Core. Can anyone help?

like image 253
Lim Avatar asked Oct 26 '25 05:10

Lim


1 Answers

Assuming your session is setup like this:

HttpContext.Session.SetString("mysession", "mySessionValue");

Then you can get the Session id:

UserSessionID = HttpContext.Session.Id;

And the user host address:

IPAddress = HttpContext.Connection.RemoteIpAddress;
like image 140
Rahul Sharma Avatar answered Oct 27 '25 18:10

Rahul Sharma



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!