private static bool IsLocalhost()
{
bool localHost = false;
try
{
System.Net.IPAddress address = System.Net.IPAddress.Parse(HttpContext.Current.Request.UserHostAddress);
Debug.WriteLine("IP Address of user: " + address, "404Handler");
IPHostEntry host = Dns.GetHostEntry(Dns.GetHostName());
Debug.WriteLine("Host Entry of local computer: " + host.HostName, "404Handler");
localHost = address.Equals(IPAddress.Loopback) || (Array.IndexOf(host.AddressList, address) >= 0);
}
catch
{
// localhost is false
}
return localHost;
}