I am creating an ASP.NET Core 8 MVC project and trying to fetch IP address with this code:
var remoteIpAddress = HttpContext.Connection.RemoteIpAddress;
But, the code throws an exception:
Address = 'remoteIpAddress.Address' threw an exception of type System.Net.Sockets.SocketException
Please help me to solve this.
I tried to update the code but I am not able to fix it.
U can try this :
HttpContext.Current.Request.UserHostAddress