ASP tutorial. NET cookie Implementation top step function code
public void ProcessRequest (HttpContext context)
{
BLL.VIDEO_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 Two
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 Cookies
if (request.cookies["userinfo"]!= null)
{
Label1.Text =
& nbsp; Server.HTMLEncode (request.cookies["userinfo"] ["username"]);
label2.text =
Server.HTMLEncode ( request.cookies["UserInfo" ["lastvisit"]);
}
/*
Cookies to achieve the top step
One user can only step on top of each article one day
Implemented with cookies.
But I point to another article when, can top step, but in return to the original article refresh, but also can top step, not a day.
It was a cookie. Re-instantiate when you click on another article
*/