ASP.NET Core: How to get remote IP address?

前端 未结 2 913
深忆病人
深忆病人 2021-02-03 13:42

I try to get remote (client) IP addres:

var ip = httpContext.Features.Get()?.RemoteIpAddress

But it works only fo

2条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-03 13:54

    Just try this code,

    var ipAddress = HttpContext.Connection.RemoteIpAddress;

    And if you have another computer in same LAN, try to connect with this pc but use user ip instead of localhost. Otherwise you will get always ::1 result.

提交回复
热议问题