问题描述
我想获取ClientIPaddress但是当我调用 Request.ServerVariables [HTTP_X_FORWARDED_FOR]
我总是得到 NULL
。
I would like to get the ClientIPaddress but when I call to Request.ServerVariables["HTTP_X_FORWARDED_FOR"]
I always get NULL
.
检查 Servervariables
列表后,我注意到 HTTP_X_FORWARDED_FOR
不在选项列表中。
After checking the list of the Servervariables
I noticed that HTTP_X_FORWARDED_FOR
is not in the list of options.
任何人都知道这是如何可行的以及如何解决?或者这个选项不在列表中并且我遗漏了一些东西是正常的。
Anyone knows how this is possible and how to solve? Or is it normal that this option is not in the list and I'm missing something.
提前致谢
推荐答案
如果请求是由代理转发的,Request.ServerVariables [HTTP_X_FORWARDED_FOR]
将只有一个值。通常,您将使用 Request.ServerVariables [REMOTE_ADDR]
获取客户端IP。
Request.ServerVariables["HTTP_X_FORWARDED_FOR"]
will only have a value, if the request was forwarded by a proxy. Usually you will get the client IP by using Request.ServerVariables["REMOTE_ADDR"]
.
这篇关于c#中serverdariables缺少HTTP_X_FORWARDED_FOR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!