asp.net-core - 如何在 ASP.NET CORE 3.1 中获取客户端 IP 地址?

标签 asp.net-core asp.net-core-webapi asp.net-core-3.1

在 Web API 项目中编写代码时如何在 ASP.NET 3.1 中获取客户端 IP 地址

最佳答案

使用本教程。希望它会帮助你。
Get client IP address in Asp.NET core 3

或者只是在您的 Controller 中使用这行代码:

var ip =HttpContext.Connection.RemoteIpAddress.ToString()

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

相关文章:

c# - 自定义标签助手如何在列表中设置 id 和名称

visual-studio - 没有 Azure 的 ASP.NET Core 个人用户帐户身份验证

asp.net-core - Entity Framework Core 1.1 OnModelCreating 方法未被调用

c# - Razor 代码块在 ASP.NET Core 3.1 中不起作用

c# - OUTPUT INSERTED Id/SCOPE_IDENTITY() 在 C# (ASP.NET Core Razor Pages) SQL 查询中返回 null,在 SQL Server Management Studio 中工作正常

c# - 隔离 EF Core 中的更改

asp.net-core - 如何在 IIS 上使用 ASP.NET Core 3.1 API 部署 Angular SPA?

authentication - 在我的 Web 应用程序 Controller 中每次 API 调用时请求访问 token 是否正确?

asp.net-core - 如何正确解析要在 ASP.NET Core 3.1 的 ConfigureServices() 中使用的服务?

web-deployment-project - 发布核心 3.1 Web 应用程序