Asp.net cookie implements the top step function code
Asp tutorial. net cookie implements the top step function code
Public void processrequest (httpcontext context)
{
Bll. video_bll = new bll. video_bll ();
If (! String. isnullorempty (context. request. querystring ["id"])
{
Int id = convert. toint32 (context. request. querystring ["id"]);
String obj = context. request. querystring ["fldname"];
Httpcookie cookie = context. request. cookies ["info"];
If (cookie! = Null & cookie. values ["id"] = id. tostring ())
{
Context. response. write ("false ");
Context. response. end ();
}
Else
{
Httpcookie cookies = new httpcookie ("info ");
Cookies. values ["userip"] = tools. tools. getuseripaddress ();
Cookies. values ["id"] = id. tostring ();
Cookies. expires = datetime. now. adddays (1 );
Context. response. cookies. add (cookies );
Video_bll.updatedigbury (obj, id );
List <videoinfo> list = video_bll.getvideo (1, "and id =" + id );
If (list. count> 0)
{
Switch (obj)
{
Case "dig ":
Context. response. write (list [0]. dig );
Context. response. end ();
Break;
Case "bury ":
Context. response. write (list [0]. bury );
Context. response. end ();
Break;
Default:
Context. response. write ("no such data ");
Break;
}
}
}
}
}
// Method 2
Response. cookies ["userinfo"] ["username"] = "patrick ";
Response. cookies ["userinfo"] ["lastvisit"] = datetime. now. tostring ();
Response. cookies ["userinfo"]. expires = datetime. now. adddays (1 );
Httpcookie acookie = new httpcookie ("userinfo ");
Acookie. values ["username"] = "patrick ";
Acookie. values ["lastvisit"] = datetime. now. tostring ();
Acookie. expires = datetime. now. adddays (1 );
Response. cookies. add (acookie );
// Read cookie
If (request. cookies ["userinfo"]! = Null)
{
Label1.text =
Server.html encode (request. cookies ["userinfo"] ["username"]);
Label2.text =
Server.html encode (request. cookies ["userinfo"] ["lastvisit"]);
}
/*
Cookie implementation top step
One user can only step on each article once in a day.
Cookie is used.
However, when I clicked another article, I could step on it. But after I refresh the original article, I could step on it again. It wasn't a day before.
It turns out that cookie is re-instantiated when another article is clicked.
*/