来自印度的MCT Maulik Patel提供了一种服务端的解决方案,很好:
if(Context.Request.ServerVariables["HTTP_VIA"]!=null) // using proxy

{
ip=Context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString(); // Return real client IP.
}
else// not using proxy or can't get the Client IP

{
ip=Context.Request.ServerVariables["REMOTE_ADDR"].ToString(); //While it can't get the Client IP, it will return proxy IP.
}
备注:
1. 有些代理是不会发给我们真实IP地址的
2. 有些客户端会因为“header_access deny”的安全设置而不发给我们IP