I am working on an MVC project in C# using dotnet version 2.2.107. I am trying to retrieve the remote IP address of the client using the UserHostAddress property: https://learn.microsoft.com/en-us/dotnet/api/system.web.httprequest.userhostaddress?view=netframework-4.8
I have included System.Web and Microsoft.AspNetCore.Http dependencies and I am trying to run this line:
string userHostAddress = Request.UserHostAddress;
Still, I am receiving the following error message:
'HttpRequest' does not contain a definition for 'UserHostAddress' and no accessible extension method 'UserHostAddress' accepting a first argument of type 'HttpRequest' could be found (are you missing a using directive or an assembly reference?)
I have also tried retrieving with ServerVariables and HttpContext.Connection.RemoteIpAddress but these aren't working.
Has anyone else encountered this problem?