如果是WebService,可以用如下方法获取客户的IP地址:
if (Context.Request.ServerVariables["HTTP_VIA"] != null) // using proxy
{
ip = Context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString(); // Return real client IP.
}
else if (Context.Request.ServerVariables["REMOTE_ADDR"] != null)// 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.
}
如果是Remoting,需要编写一个吸取器来获取客户的IP地址。