.Net5 获取客户端IP地址
1、NuGet安装 Microsoft.AspNetCore.Http
2、services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
3、获取
1 HttpContextAccessor context = new HttpContextAccessor(); 2 var IP = context.HttpContext?.Connection.RemoteIpAddress.ToString();