HiveBrain v1.2.0
Get Started
← Back to all entries
snippetcsharpCritical

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

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
netasphowcoreclientaddressget

Problem

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.

Solution

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;

Code Snippets

var remoteIpAddress = request.HttpContext.Connection.RemoteIpAddress;

Context

Stack Overflow Q#28664686, score: 526

Revisions (0)

No revisions yet.