asp.net cookies to achieve the top step function code

Source: Internet
Author: User
Tags datetime

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

*/

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.