1

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?

Lim
  • 89
  • 1
  • 10

1 Answers1

3

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;
Rahul Sharma
  • 7,768
  • 2
  • 28
  • 54