Skip to content

Instantly share code, notes, and snippets.

@karlseguin
Created January 17, 2011 12:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save karlseguin/782799 to your computer and use it in GitHub Desktop.
Save karlseguin/782799 to your computer and use it in GitHub Desktop.
try to bust through proxies for a remote address
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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment