获取真实IP
public static string GetRealIP()
{
string ip;
try
{
HttpRequest request = HttpContext.Current.Request;
if (request.ServerVariables["HTTP_VIA"] != null)
{
ip = request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString().Split(',')[0].Trim();
}
else
{
ip = request.UserHostAddress;
}
}
catch (Exception e)
{
throw e;
}
return ip;
}
获取代理IP
public static string GetViaIP()
{
string viaIp = null;
try
{
HttpRequest request = HttpContext.Current.Request;
if (request.ServerVariables["HTTP_VIA"] != null)
{
viaIp = request.UserHostAddress;
}
}
catch (Exception e)
{
throw e;
}
return viaIp;
}
Appendix
what proxy server are you using? if you are using ISA, take a look at:
http://www.isaserver.org/articles/Configuring_a_ISP_Colocated_WebSMTPISA_Server.html
basically, you need to set the proxy server in transparent mode
本文提供了一种通过C#代码获取客户端真实IP地址及代理服务器IP的方法,并附带了透明代理设置的相关链接。

194

被折叠的 条评论
为什么被折叠?



