string ip = Request.UserHostAddress;//获取本机ip 也是cookie的名称
if (Request.Cookies[ip] == null)//判断cookie中是否有此ip的cookie
{
Response.SetCookie(new HttpCookie(ip, "1"));//新建一个cookie
textbox1.Text = Request.Cookies[ip].Value;//把值返回给浏览器
}
else
{
string a=Request.Cookies[ip].Value;
int b=Convert.ToInt32(a);
Request.Cookies[ip].Value=Convert.ToString(b+1);//修改此cookie的value值
Response.Cookies.Set(Request.Cookies[ip]);//更新此cookie
textbox1.Text = Request.Cookies[ip].Value;//返回客户端
//在此过程中至始至终一个ip只能有一个cookie 不要把更新vlaue后的cookie附到
//一个新建的cookie中以免导致浏览器关闭后cookie重置现象
}