asp.net Core API 获取ip地址

1.nuget 引用 Microsoft.AspNetCore.HttpOverrides

2.app.UseForwardedHeaders(new ForwardedHeadersOptions { ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto });

3.使用

var ip = HttpContext.Connection.RemoteIpAddress;//ip地址
var port = HttpContext.Connection.RemotePort;//端口

 

上一篇:asp.net core 3.1 cookie httpOnly 登录验证


下一篇:asp.net core 3.1 源码学习(二)