Web Sitenize Giren Kullanıcıların IP lerini Öğrenme - Asp.Net

Asp.net üzerinde hazırladığınız web formunuzda gelen ziyaretçilerin ip sini tutmak veya görmek için aşağıdaki kodlar işinizi görecektir.

 public partial class _default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] != null)
            {
                ipgor.Text = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();
            }
            else if (HttpContext.Current.Request.UserHostAddress.Length != 0)
            {
                ipgor.Text = HttpContext.Current.Request.UserHostAddress;
            }
        }
    }


Not: Projeyi kendi makinanızda test ettiğinizde localhost IP adresi olan 127.0.0.1 adresini ya da :::1 gibi boş bir değer alabilirsiniz. Projeyi hostunuza attığınızda doğru bilgiyi göreceksiniz.

Yorumlar

Bu blogdaki popüler yayınlar

Windows’ta Uzantısı Değiştirilmiş Dosyaları Tespit Etme: Powershell ile Pratik Yöntem

Asp.Net ile T.C. Kimlik Doğrulama (Mernis) Web Service ile

Chrome HSTS Hatası Nedir ve Nasıl Çözülür?