c# - c# 中的服务器变量缺少 HTTP_X_FORWARDED_FOR

标签 c# asp.net ip

我想获取 ClientIPaddress,但是当我调用 Request.ServerVariables["HTTP_X_FORWARDED_FOR"] 时,我总是得到 NULL

检查完 Servervariables 列表后,我注意到 HTTP_X_FORWARDED_FOR 不在选项列表中。

任何人都知道这是怎么可能的以及如何解决?或者这个选项不在列表中是正常的,我遗漏了什么。

提前致谢

最佳答案

Request.ServerVariables["HTTP_X_FORWARDED_FOR"] 只有在请求由代理转发时才有值。通常,您将使用 Request.ServerVariables["REMOTE_ADDR"] 获取客户端 IP。

关于c# - c# 中的服务器变量缺少 HTTP_X_FORWARDED_FOR,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17521277/

相关文章:

c# - 我可以说事件和委托(delegate)之间的关系采用复合模式吗?

c# - 相对 URL 在 System.Web.UI.UserControl 中不起作用

asp.net - RazorEngine 3.6.3 无法从 'string' 转换为“RazorEngine.Templated.ITemplateKey”

php - 在自治系统编号 (ASN) 中获取 IP

c# - 如何获得枚举数作为常量?

c# - SharpDX ResizeBuffers 的 Resize 事件错误 0x887A0001

c# - “索引超出范围。必须为非负数且小于集合的大小。\r\n参数名称 : index

c# - GridView HeaderRow.TableSection 错误

c# - 如何在 C# 中从网络上的 IP 访问打印机名称?

wordpress - 使用 htaccess 按用户主机名阻止请求