Wednesday, July 21, 2010

Get the IP address of the browser in.Net

string address = string.Empty;
address = ControllerContext.HttpContext.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
// check if the request doesnt have forward remote address
if (address == null || (address != null && address.Length < 1))
{
address = HttpContext.Request.ServerVariables["REMOTE_ADDR"];
}

No comments:

Post a Comment