Get Client IP Address in ASP.NET Core 2.x
In classic ASP.NET we used to get client IP Address by Request.UserHostAddress. But this does not apply to ASP.NET Core 2.0. We need a different way to retrieve HTTP Request information. 1. Define a variable in your MVC controller private IHttpContextAccessor _accessor; 2. DI into the controller's constructor public SomeController(IHttpContextAccessor accessor) { _accessor = accessor; …