public
Created

try to bust through proxies for a remote address

  • Download Gist
gistfile1.cs
C#
1 2 3 4 5 6 7 8 9 10 11 12 13 14
private static readonly string[] _ipHeaderOrder = new[] { "HTTP_X_FORWARDED_FOR", "HTTP_X_CLUSTER_CLIENT_IP", "REMOTE_ADDR" };
 
public static string ClientAddress(this HttpRequest request)
{
foreach (string header in _ipHeaderOrder)
{
string ipAddress = request.ServerVariables[header];
if (ipAddress != null)
{
return ipAddress;
}
}
return string.Empty;
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.