.net HTTP_X_FORWARDED_FOR在localhost上为NULL [英] .net HTTP_X_FORWARDED_FOR NULL on localhost

查看:237
本文介绍了.net HTTP_X_FORWARDED_FOR在localhost上为NULL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

道歉,如果已经回答了其他地方,我找不到它。

Apologises if this has been answered else where, I could not find it.

如果没有,我试图找到访问该网站的机器的原始IP。

In the case it has not, I am trying to find the original IP of a machine who has accessed the site.

在我的基本理解中,变量 HTTP_X_FORWARDED_FOR 将显示用户的IP,无论代理和其他过滤器如何。如果这是真的,我正在尝试编码,但我得到一个空字符串

In my basic understanding, the variable HTTP_X_FORWARDED_FOR will display the user's IP regardless of proxy's and other filters. if this is true, I am trying to code this but I get a null string

System.Web.HttpContext context = System.Web.HttpContext.Current;
string ipAddress = context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]; 

可能出现的问题 HTTP_X_FORWARDED_FOR 未出现在HTTP HEADERS /服务器变量列表中,还是我使用的是localhost?使用 REMOTE_ADDR ,将显示localhost IP。

Possible problems are HTTP_X_FORWARDED_FOR doesn't appear in the HTTP HEADERS / server variable list, or I am using localhost? Using REMOTE_ADDR, the localhost IP is displayed.

我是在正确的位置还是我的理解不正确?

Am I on the right lines or is my understanding incorrect?

谢谢

推荐答案

HTTP_X_FORWARDED_FOR标头通常包含代理值,因此您不会在本地计算机上看到任何内容,因为您没有通过任何代理

HTTP_X_FORWARDED_FOR header usually hold proxy values so it is normal you dont see any content on your local machine since you are not going through any proxies

这篇关于.net HTTP_X_FORWARDED_FOR在localhost上为NULL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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