Try This....
public static string GetIPAddress(HttpRequestBase request)
{
string ip = string.Empty;
try
{
ip = request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (!string.IsNullOrEmpty(ip))
{
if (ip.IndexOf(",") > 0)
{
string[] allIps = ip.Split(',');
int le = allIps.Length - 1;
ip = allIps[le];
}
}
else
{
ip = request.UserHostAddress;
}
HttpContext.Current.Session["IpAddress"] = ip;
}
catch (Exception ex)
{
throw ex;
}
return ip;
}