asp.net Core API 获取ip地址

原文: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 API 获取ip地址

上一篇:AcWing393 雇佣收银员(差分约束)


下一篇:Windows 服务初试