1.NUGET安装 Microsoft.AspNetCore.Http
2.在 startup.cs 的 ConfigureServices 中注入ip
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();3.获取ip
HttpContextAccessor context = new HttpContextAccessor();
var ip = context.HttpContext?.Connection.RemoteIpAddress.ToString();
- 本文标题: NETCore获取客户端IP信息
- 文章分类:【.NET/Web】
- 非特殊说明,本文版权归【胡同里的砖头】个人博客 所有,转载请注明出处.