Jump to content

Asp.net Ile Basit Online Ziyaretçi Sayacı


Bitmap
 Share

Recommended Posts

Merhaba arkadaşlar, Arşivimi karıştırırken, çok eskiden yazdığım bir yazıya denk geldim. Şimdi kodunu yazdım ve belki işinize yarar diye ekliyorum. Sitelerde gördüğümüz Online Ziyaretçi Sayacını yapmak asp.net'te çok kolay. veritabanına vs hiç ihtiyacımız yok. Global.asax dosyasını kullanarak basit bir sayaç yapabiliriz. (tam olarak garantili değildir. -1 +1 hata payı olabilir sayılarda session ve uygulama durumuna göre.)

 

  1. Temel olarak,
  2. Uygulamayı başlatırken Sayısı 0'lıyoruz.
  3. Bir Session Başladığında ise Bu sayıyı bir arttırıyoruz.
  4. Session Bittiğinde ise bir azaltıyoruz.  Session ortalama 15 dk sonra devre dışı kalıyor.
  5. En son uygulama kapatıldığında ise hafızadan siliyoruz.

 

Çıktısı aşağıdaki şekildedir.:
 

pre_1429282322__capture.png

 

 

Global.asax file :

using System;

namespace OnlineZiyaretci
{
    public class Global : System.Web.HttpApplication
    {

        protected void Application_Start(object sender, EventArgs e)
        {
            Application.Add("ZiyaretciSayisi", 0);

        }

        protected void Session_Start(object sender, EventArgs e)
        {
            
            Application["ZiyaretciSayisi"] = Convert.ToInt32(Application["ZiyaretciSayisi"]) +1;
            
        }

        protected void Session_End(object sender, EventArgs e)
        {
            Application["ZiyaretciSayisi"] = Convert.ToInt32(Application["ZiyaretciSayisi"]) -1;
        }

        protected void Application_End(object sender, EventArgs e)
        {
            Application.Remove("ZiyaretciSayisi");
        }
    }
}

Proje Dosyasını Buradan (Dropbox) indirebilirsiniz.

Edited by Bitmap
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...