Я могу просто дать вам мой результат теста.
Я создаю веб-приложение и вручную устанавливаю его на 2 экземпляра.
Мой код:
public string GetIP()
{
string HTTP_X_FORWARDED_FOR = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
string REMOTE_ADDR = Request.ServerVariables["REMOTE_ADDR"];
string UserHostAddress = Request.UserHostAddress;
string WEBSITE_INSTANCE_ID = Environment.GetEnvironmentVariable("WEBSITE_INSTANCE_ID");
return Newtonsoft.Json.JsonConvert.SerializeObject(new { HTTP_X_FORWARDED_FOR = HTTP_X_FORWARDED_FOR, REMOTE_ADDR = REMOTE_ADDR, UserHostAddress = UserHostAddress, WEBSITE_INSTANCE_ID = WEBSITE_INSTANCE_ID });
}
Результат:
// First request from 13.70.19.163
{"HTTP_X_FORWARDED_FOR":"13.70.19.163:50331","REMOTE_ADDR":"13.70.19.163","UserHostAddress":"13.70.19.163","WEBSITE_INSTANCE_ID":"2b4ef85523c8628779b336b1ae7771fb0c5e289014ef47912d911dceb47ba032"}
// Second request from 65.52.178.194
{"HTTP_X_FORWARDED_FOR":"65.52.178.194:31190","REMOTE_ADDR":"65.52.178.194","UserHostAddress":"65.52.178.194","WEBSITE_INSTANCE_ID":"2b4ef85523c8628779b336b1ae7771fb0c5e289014ef47912d911dceb47ba032"}
// Another request from 223.67.26.144. This request is redirected to a different instance
{"HTTP_X_FORWARDED_FOR":"223.67.26.144:2732","REMOTE_ADDR":"223.67.26.144","UserHostAddress":"223.67.26.144","WEBSITE_INSTANCE_ID":"76deb6ae830639a9e41a93b4cc30ee9961483023510e33e97582dc1e2ac11a99"}
Вывод:
Request.ServerVariables["HTTP_X_FORWARDED_FOR"]
, REMOTE_ADDR
и UserHostAddress
все могут получить правильный IP-адрес клиента.