System.Web.HttpContext.Current.Request.UserHostAddress; [英] System.Web.HttpContext.Current.Request.UserHostAddress;

查看:597
本文介绍了System.Web.HttpContext.Current.Request.UserHostAddress;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用下面的code,以获得用户I.P.地址,但一些奇怪的事情正在发生。我,每次如果我在我的桌面上或在我的iPhone无论接收相同的IP地址。我为我们的网络上,其中的Web服务器住的时候我打的页面从我的桌面,但在我的iPhone我是不是即使在建设。我以前没有碰到这个问题,IP地址,我取回是一个内部分配给Web服务器。

I am using the following code to obtain the user I.P. address but something strange is happening. I am, receiving the same ip address every time no matter if I am on my desktop or on my iPhone. I am on our network where the web servers live when I hit the page from my desktop but on my iPhone I was not even in the building. I have not run into this issue before, the ip address that I am getting back is an internal one assigned to the web servers.

string ip = System.Web.HttpContext.Current.Request.UserHostAddress;
Response.Write(ip);

之外我的网络我仍然得到相同的IP地址172.16.0.22这是一个路由器的地址,不是我们的外部IP。有没有一种方式来获得外部IP地址。

Outside of my network I still get the same ip address 172.16.0.22 which is a router address, not our external ip. Is there a way to obtain the external ip address.

推荐答案

看到这个链接的http:// thepcspy。 COM /读/ getting_the_real_ip_of_your_users /

        // Look for a proxy address first
        _ip = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];

        // If there is no proxy, get the standard remote address
        if (_ip == null || _ip.ToLower() == "unknown")
            _ip = Request.ServerVariables["REMOTE_ADDR"];

这篇关于System.Web.HttpContext.Current.Request.UserHostAddress;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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