Asp.net cookie implements the top step function code

Source: Internet
Author: User
Tags html encode

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.

*/

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.