当前位置: 移动技术网 > IT编程>开发语言>.net > .net core 获取本地ip及request请求端口

.net core 获取本地ip及request请求端口

2019年01月19日  | 移动技术网IT编程  | 我要评论

bk控制变压器,青春荷尔蒙4,郝建小品全集

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"

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网