Skip to content

Commit

Permalink
Combine both the REMOTE_ADDR header (which is the connecting device's…
Browse files Browse the repository at this point in the history
… IP address), plus the HTTP_X_FORWARDED_FOR header if present (which is set by some proxy servers and load balancers). This allows us to have a unique per-user view, even when behind a proxy or load balancer.
  • Loading branch information
Adam Nelson committed May 29, 2014
1 parent 5f84308 commit 8607fe0
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion StackExchange.Profiling/IpAddressProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,15 @@ public class IpAddressIdentity : IUserProvider
{
/// <summary>
/// Returns the paramter HttpRequest's client ip address.
/// We combine both the REMOTE_ADDR header (which is the connecting device's IP address),
/// plus the HTTP_X_FORWARDED_FOR header if present (which is set by some proxy
/// servers and load balancers). This allows us to have a unique per-user view, even
/// when behind a proxy or load balancer.
/// </summary>
public string GetUser(HttpRequest request)
{
return request.ServerVariables["REMOTE_ADDR"] ?? "";
return string.Format("{0}, {1}", request.ServerVariables["REMOTE_ADDR"] ?? "",
request.ServerVariables["HTTP_X_FORWARDED_FOR"] ?? "");
}
}
}

0 comments on commit 8607fe0

Please sign in to comment.