Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTTP_X_FORWARDED_FOR missing from servervariables in c#

Tags:

c#

asp.net

ip

I would like to get the ClientIPaddress but when I call to Request.ServerVariables["HTTP_X_FORWARDED_FOR"] I always get NULL.

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.

Thanks in advance

like image 317
thomvlau Avatar asked Jul 08 '13 07:07

thomvlau


1 Answers

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"].

like image 63
dwtm.ts Avatar answered Nov 09 '22 04:11

dwtm.ts