访问计数器

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;

using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        int ivs;            
        if(Request.Cookies["vnumber"]==null)       
        {                    
            ivs=1;                  
            Response.Cookies["vnumber"].Value=ivs.ToString();    
              
            Response.Cookies["vnumber"].Expires=DateTime.Now.AddYears(2);          
             
            Response.Cookies["flag"].Value="ok";          
           
            Response.Cookies["flag"].Expires=DateTime.Now.AddMinutes(10);        
        }        
        else          
        {             
                     
            if(Request.Cookies["flag"]==null)            
            {               
                    
                ivs=int.Parse(Request.Cookies["vnumber"].Value)+1;              
                      
                Response.Cookies["vnumber"].Value=ivs.ToString();             
                         
                Response.Cookies["vnumber"].Expires=DateTime.Now.AddYears(2); 
                           
                Response.Cookies["flag"].Value="ok";                              
                Response.Cookies["flag"].Expires=DateTime.Now.AddMinutes(10);            
            }            
            else            
            {               
                ivs=int.Parse(Request.Cookies["vnumber"].Value);         
            }          
        }                     
        this.message.Text="<h3>你是第"+ivs.ToString()+"次访问本页面</h3>";
    }
}

你可能感兴趣的:(访问计数器)