17 Ekim 2016 Pazartesi

Asp.Net İp Kontrol

public static class ipKontrol { public static string IP() {
string ip = "";
if (HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] != null) {
ip = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (!string.IsNullOrEmpty(ip)) { string[] ipRange = ip.Split(",".ToCharArray()); ip = ipRange[0];
}
}
if (string.IsNullOrEmpty(ip)) if (HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"] != null)
ip = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"].ToString(); ip = ip.Trim(); return ip;
}
}
Kullanımı: string ip = ipKontrol.IP();

Hiç yorum yok:

Yorum Gönder