为什么Request.UserHostAddress给出不同的结果

时间:2019-04-05 10:57:07

标签: c# asp.net iis dns ip

我正在尝试使用public IP获得Request.UserHostAddress。对我的一个项目来说效果很好
但是当我在具有不同域名的另一台计算机上部署同一项目时,它向我显示了私有IP

我的代码:

   public string GetIPAddress()
{
    try
    {
        return Request.UserHostAddress;
    }
    catch (Exception ex)
    {
        return ex.ToString();
    }
}

如果同一项目部署了一个网络,则在与using domain and public IP both (it gave me public IP)打开时可以正常工作。但是,当同一项目部署在另一个网络上并使用公共IP打开时,它给了我同样的result same like first one,但是当尝试使用domain name it showed me private IP.

Why above condition happen? what is going wrong any domain setting or network setting?

0 个答案:

没有答案
相关问题