I have the following code:
string ip = Request.ServerVariables["REMOTE_ADDR"];
Which, in the test environment does return the user IP addrress, but when we deploy the website to production, this variable has the IP of the server where the application is hosted. Any help?
My guess is that there is a proxy in the middle. Use
HTTP_X_FORWARDED_FORfirst, and if that’s null, then useREMOTE_ADDRFrom the MSDN article:
UPDATE:
If it’s a load balancer that you have have settings changed on, you should ask to see if they can have the origination IP passed through. I know this can be done with Microsoft’s ISA server.
If that’s not an option, there are these other server variables that you can try and see if they produce a result: