How to get in ASP.NET Core 3.0 API the client API
On the start up class I have added this line:
services.AddControllersWithViews();
services.AddSingleton <IActionContextAccessor,ActionContextAccessor>();
IndexController.cs
private readonly IActionContextAccessor _accessor;
public IndexController(IActionContextAccessor accessor)
{
_accessor = accessor;
}
[HttpGet()]
[Route("[action]")]
public string GetIPAddress(string id)
{
//var ip = HttpContext.Connection.RemoteIpAddress.ToString();
var ip = _accessor.ActionContext.HttpContext.Connection.RemoteIpAddress.ToString();
return ip;
}
After trying many methods, we can't get the IP address of the client. The result is:
::1