How to get Client IP address in ASP.NET Core 2.1

前端 未结 7 684
再見小時候
再見小時候 2021-02-02 09:21

I\'m working on ASP.Net Core 2.1 with Angular Template provided by Microsoft Visual Studio 2017. My Client App is working fine. After competition of User Authentication, I want

7条回答
  •  温柔的废话
    2021-02-02 10:04

    This works for me on .Net Core 2.2:

    IPHostEntry heserver = Dns.GetHostEntry(Dns.GetHostName());
    
    var ipAddress = heserver.AddressList.ToList().Where(p => p.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork).FirstOrDefault().ToString();
    

提交回复
热议问题