C# .net core 获取客户端IP地址

 Startup 文件 注册服务 

 public void ConfigureServices(IServiceCollection services)
{ services.AddSingleton
<IHttpContextAccessor, HttpContextAccessor>(); }

获取IP地址

private readonly IHttpContextAccessor _httpContextAccessor;

public HomeController(IHttpContextAccessor httpContextAccessor){
  _httpContextAccessor
= httpContextAccessor; } public object get(){   return _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString(); }

 

C# .net core 获取客户端IP地址

上一篇:QTP windows标准对象


下一篇:21世纪 Windows 安装 Flash 插件