Based on this , I think a more modern and elegant solution would be to do the following:
string ipAddress;
Microsoft.Owin.IOwinContext owinContext = Request.GetOwinContext();
if (owinContext != null)
{
ipAddress = owinContext.Request.RemoteIpAddress;
}
or, if you do not need to test the OWIN null context, you can simply use this single-line font:
string ipAddress = Request.GetOwinContext().Request.RemoteIpAddress;
source
share