简体   繁体   English

从客户端而不是前端服务器获取IP地址

[英]Getting IP address from client, not front-end server

I have a WEB API that has a backend in C# (using DDD) and a frontend that uses it in Angular hosted in different servers. 我有一个WEB API,该API在C#中具有后端(使用DDD),并且在不同服务器上托管的Angular中具有使用它的前端。 I want to get my client's IP when they log in (for audit purposes), when I try to run my code through postman it works but when making the request through the frontend, it always return the frontend server IP. 我想在客户端登录时(出于审计目的)获取客户端的IP,当我尝试通过邮递员运行我的代码时,它可以工作,但是当通过前端发出请求时,它总是返回前端服务器IP。

I have tried using IpPublicKnowledge which is a Nuget package that gets the IP using a webpage. 我尝试使用IpPublicKnowledge ,它是一个Nuget程序包,可使用网页获取IP。

I have tried different ways that get the IP from the HttpContext but they also return Frontend server IP, not the client's IO. 我尝试了多种方法来从HttpContext获取IP,但它们还会返回Frontend服务器IP,而不是客户端的IO。

I am answering this in case anyone wants to know, I tried to get the IP through HTTP_X_FORWARDED_FOR but it wasn't reliable enough. 如果有人想知道,我会回答这个问题,我试图通过HTTP_X_FORWARDED_FOR获取IP,但是它不够可靠。 So what solved it was to create a php server that got the ip from the client and have the frontend application use it and send it to the backend. 因此解决问题的方法是创建一个从客户端获取ip的php服务器,并让前端应用程序使用它并将其发送到后端。 @Chetan Ranpariya also said this and it ended up being my last resort. @Chetan Ranpariya也这样说,这最终是我的最后选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM