c# - 如何在 ASP.NET Core 中获取客户端 IP 地址?

标签 c# asp.net-core asp.net-core-mvc

能否请您告诉我如何在使用 MVC 6 时在 ASP.NET 中获取客户端 IP 地址。 Request.ServerVariables["REMOTE_ADDR"] 不起作用。

最佳答案

API 已更新。不确定它何时更改但according to Damien Edwards在 12 月下旬,您现在可以这样做:

var remoteIpAddress = request.HttpContext.Connection.RemoteIpAddress;

关于c# - 如何在 ASP.NET Core 中获取客户端 IP 地址?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28664686/

相关文章:

c# - 在 Visual Studio 中增加构建修订号

javascript - 路由未按预期工作

c# - 如何在 ASP.NET Core 应用程序中使用位图资源?

c# - ASP.NET 核心 (MVC) : Can't get to the Login HttpPost action in controller

c# - 使用 LINQ2SQL 在 ASP.NET MVC 中的各种模型存储库之间共享数据上下文

c# - MySql + Entity Framework = 每个派生表必须有自己的别名

c# - 如何在尊重路由配置的同时解析 Kentico Cloud 中的内容项链接?

c# - .net core [授权] 将 ClaimsIdentity 与 AAD 组结合使用

asp.net - 使用 ASP.NET MVC 6 在 Web.config 中设置 IIS 设置

c# - MVC 6 HttpResponseException