放肆看

导航

 

1.NUGET安装 Microsoft.AspNetCore.Http

 

2.在 startup.cs 的 ConfigureServices 中注入

services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();

 

3.获取ip

HttpContextAccessor context = new HttpContextAccessor();
var ip = context.HttpContext?.Connection.RemoteIpAddress.ToString();

 

posted on 2019-02-13 14:46  放肆看  阅读(1211)  评论(1编辑  收藏  举报