登录系统的IPAddress [英] IPAddress of a login system

查看:136
本文介绍了登录系统的IPAddress的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用下面的代码。

protected string GetUserIP()
{
    string strUserIP = string.Empty;
    if (HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] != null)
    {
        strUserIP = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();
    }
    else if (HttpContext.Current.Request.UserHostAddress.Length != 0)
    {
        strUserIP = HttpContext.Current.Request.UserHostAddress;
    }
    return strUserIP;
}

我得到的格式为 :: 1的IP地址

如何获得系统的正确IP地址。

How do I get the correct IP address of a system.

推荐答案

如果你在网络服务器上使用它是 localhost :: 1 将获得正确的。

It is of localhost ::1 if you use on web server you will get the correct one.

虽然这取决于用户访问您的应用程序的网络配置。

Though it will depend on the configuration of the network from where the user is accessing your application.

可以有 firewall ,它不会公开客户端系统的实际IP。

There can be firewall which doesn't expose the actual IP of the client system.

这篇关于登录系统的IPAddress的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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