用户计算机的IP地址

用户计算机的IP地址

本文介绍了查找客户端/用户计算机的IP地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在asp.net mvc中有一个web api。在Post请求,我想获得客户端/用户的机器的IP地址。我试过以下代码,但获取服务器的IP地址。请帮助



我尝试过:



I have a web api in asp.net mvc. On Post request, i want to get ip address of client's/users's machine. I have tried following code,but getting the ip address of server. Please help

What I have tried:

HttpContext.Current.Request.UserHostAddress;










string ip5 = HttpContext.Current.Request.Params["HTTP_CLIENT_IP"] ?? HttpContext.Current.Request.UserHostAddress;













ip7 = HttpContext.Current.Request.UrlReferrer.ToString();










string ip10 = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
              if (ip10 != null || ip10 != String.Empty)
              {
                  ip10 = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
              }

推荐答案

HttpContext.Current.Request.UserHostAddress;

在我的应用程序中,它运行正常。

也许在您处理帖子的代码中,您指定了更多的地方客户机的ip。断点并检查HttpContext.Current.Request.UserHostAddress的值可以帮助你。

in my application and it works ok.
Perhaps in the code where you process the post there are more places where you assign the ip of the machine of the client. A breakpoint and exam the value of HttpContext.Current.Request.UserHostAddress could help you.



这篇关于查找客户端/用户计算机的IP地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 07:30