如何在C#API中获取客户端IP地址 [英] How to get client IP address in C# API

查看:710
本文介绍了如何在C#API中获取客户端IP地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI

我要求我必须获取请求我的c#Web API的客户端的IP地址,例如,如果移动电话呼叫我的WebAPI,那么WebAPI应该识别IP移动电话的地址,我真正想要的是所请求设备的IP地址



我尝试了什么:



我试过检索请求对象的所有属性但没有人帮助我

HI
I have a requirement that I have to get the IP address of the client that requested my c# Web API, for example, if a mobile call my WebAPI , then WebAPI should identify the IP address of the mobile,what i actually want is the IP address of the requested device

What I have tried:

I have tried retrieving all the properties of the request object but none helped me

推荐答案

你做不到。它不是一个真正的IP地址,它是互联网接触点的IP地址,对于移动设备而言,它将由电话公司提供,并且随着电话在网络中移动并连接和断开连接,这可能会有所不同。 。它也可能被许多不同的移动设备共享,就像宽带连接提供路由器的IP地址一样,而不是提供请求的桌面或WiFi设备。



为什么你认为你需要手机的IP?它不太可能有用,因为它纯粹是暂时的,没有真正的地理位置,所以你甚至不能用它来告诉你用户在哪里!
You can't. It's not a "real" IP address, it's the IP address of the point of contact to the internet, which for a mobile would be up to the phone company to provide and which will probably vary as the phone moves around networks and connects and disconnects. It will also be likely to be shared by a number of different mobile devices as any one time in the same way that a broadband connection gives the IP address of the router, not the desktop or WiFi device making the request.

Why do you think you need the IP of the phone? It's unlikely to be helpful as it is purely temporary and has no "real" geolocation so you can't even use it to tell you where a user is!


如果你采取了分钟到谷歌你可以找到这个常见问题的答案 - 你无法获得客户端IP。或者他们的MAC地址以防你的下一个问题。
If you'd taken a minute to google you could have found the answer to this very frequently asked question - you can't get the client IP. Or their MAC address in case that is your next question.


你有没有尝试通过ASP.NET Web API获取客户端IP [ ^ ]?


这篇关于如何在C#API中获取客户端IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆