在我们的启动类的 Configure方法里加上。
app.UseForwardedHeaders(new ForwardedHeadersOptions { ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto });
记得添加引用:
using Microsoft.AspNetCore.HttpOverrides
在你的应用中 获取客户端IP地址:
Request.HttpContext.Connection.RemoteIpAddress;
获取客户端访问端口号:
Request.HttpContext.Connection.RemotePort;