diff --git a/StackExchange.Profiling/IpAddressProvider.cs b/StackExchange.Profiling/IpAddressProvider.cs index 8f3f2409b..f9c430cc1 100644 --- a/StackExchange.Profiling/IpAddressProvider.cs +++ b/StackExchange.Profiling/IpAddressProvider.cs @@ -1,4 +1,5 @@ -using System.Web; +using System; +using System.Web; namespace StackExchange.Profiling { @@ -16,8 +17,15 @@ public class IpAddressIdentity : IUserProvider /// public string GetUser(HttpRequest request) { - return string.Format("{0}, {1}", request.ServerVariables["REMOTE_ADDR"] ?? "", - request.ServerVariables["HTTP_X_FORWARDED_FOR"] ?? ""); + // If there's no X_FORWARDED_FOR header, just return REMOTE_ADDR + if (String.IsNullOrWhiteSpace(request.ServerVariables["HTTP_X_FORWARDED_FOR"])) + { + return request.ServerVariables["REMOTE_ADDR"] ?? ""; + } + + // Otherwise return the concatenation of the REMOTE_ADDR and the X_FORWARDED_FOR header + return string.Format("{0} - {1}", request.ServerVariables["REMOTE_ADDR"] ?? "", + request.ServerVariables["HTTP_X_FORWARDED_FOR"]); } } }