【问题标题】:How to disable Google proxy used for Chrome's mobile data compression in C#?如何在 C# 中禁用用于 Chrome 移动数据压缩的 Google 代理?
【发布时间】:2017-09-06 18:32:15
【问题描述】:

当用户想要登录我的网站(C#、MVC)时,我通过以下代码将 IP 地址保存在 cookie 中:

   HttpContext.Current.Request.UserHostAddress

当我想再次获取IP地址并与cookie上保存的IP进行比较时,用户重定向到帐户后,IP已更改为:“66.249.93.88”

经过一些研究,我发现这是因为谷歌代理用于 Chrome 的移动数据压缩,当我在设置中禁用它时一切正常。

现在我想知道是否有一种方法可以通过代码禁用数据压缩或...以防止 IP 更改?

改成代理IP后有没有办法找到主IP地址?

我不希望我的用户更改其 Chrome 的移动设置。

【问题讨论】:

标签: c# google-chrome cookies proxy


【解决方案1】:

感谢@JoshLee 提供此链接:

Read X-Forwarded-For header

和:

As a site owner, how do I perform IP geo-targeting?
The IP address of your device is forwarded to the destination server via the 
X-Forwarded-For header. Site owners should check for this header to 
correctly determine the location of the user based on client's IP 

此功能可以帮助您获取正确的IP地址:

public static string GetRequestIp()
    {
        if (HttpContext.Current.Request.Headers["X-Forwarded-For"] != null)
        {
            return HttpContext.Current.Request.Headers["X-Forwarded-For"].Split(new char[] { ',' })[0].ToString();
        }

        return HttpContext.Current.Request.UserHostAddress;
    }

【讨论】:

    猜你喜欢
    • 2015-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-31
    • 1970-01-01
    • 2021-09-09
    相关资源
    最近更新 更多