Why does ServerVariable[“REMOTE_ADDR”] returns the server IP?

后端 未结 3 523
无人共我
无人共我 2020-12-03 01:45

I have the following code:

string ip = Request.ServerVariables[\"REMOTE_ADDR\"];

Which, in the test environment does return the user IP add

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-03 02:20

    Why do you use old, VB-style server variables instead of Request.UserHostAddress?

    See MSDN Library.

    As the others have stated, you will get the IP address of the reverse proxy/SSL terminator if it doesn't make the requests look like they come from the original client (As is possible at least in ISA server, and probably in most other reverse proxies).

    If not, you will get the public address of the client (which is probably a router address at the client site, as most LANs are NAT-ed).

    How does your setup in the production environment differ from your test environment?

    Are you actually getting the IP address of the Web server, or of some other server in the same network?

提交回复
热议问题