How do I get client IP address in ASP.NET CORE?

eadam picture eadam · Feb 23, 2015 · Viewed 146.3k times · Source

Can you please let me know how to get client IP address in ASP.NET when using MVC 6. Request.ServerVariables["REMOTE_ADDR"] does not work.

Answer

David Peden picture David Peden · Feb 12, 2016

The API has been updated. Not sure when it changed but according to Damien Edwards in late December, you can now do this:

var remoteIpAddress = request.HttpContext.Connection.RemoteIpAddress;