24 Aralık 2015 Perşembe

Asp.net ile ip adresini alma ve text dosyasına yazma


öncelikle  using System.IO; kütüphanesini projemize dahil ediyoruz.

string IP = "";
        if (HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] != null)
        {
            IP = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();
        }
        else if (HttpContext.Current.Request.UserHostAddress.Length != 0)
        {
            IP = HttpContext.Current.Request.UserHostAddress;
        }

        

        StreamWriter sw = File.AppendText(Server.MapPath("~/log.txt"));
        sw.WriteLine(IP + "-->" + DateTime.Now);
        sw.Flush();
        sw.Close();

Hiç yorum yok:

Yorum Gönder