1.获取ip和端口

string str = (Request.HttpContext.Connection.LocalIpAddress.MapToIPv4().ToString() + ":" + Request.HttpContext.Connection.LocalPort);

输出str,会得到当前服务器的IP及端口("127.0.0.1:5001")

2.获取ip

var ip = HttpContext.Request.Headers["X-Forwarded-For"].FirstOrDefault();
if (string.IsNullOrEmpty(ip))
{
    ip = HttpContext.Connection.RemoteIpAddress.ToString();
}
return ip;  "127.0.0.1"

相关文章:

  • 2021-12-15
  • 2022-12-23
  • 2022-12-23
  • 2021-08-03
  • 2019-09-23
  • 2021-12-05
  • 2018-11-26
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-03
  • 2022-12-23
  • 2021-12-05
  • 2022-12-23
相关资源
相似解决方案