. NET News click Changes to avoid malicious refreshes

Source: Internet
Author: User


DataTable dt = BLL. Getnewsbyid (ID);//Get news details based on ID if (dt! = null && dt. Rows.Count > 0) {//click Modify Scheme string title = dt. rows[0]["title"]. ToString (); Determine if there is a cookie HttpCookie cookie = context. request.cookies["Newstitle"]; if (cookie = = null) {//Create a new cookie cookie = new Httpcooki E ("Newstitle"); Cookies. Value = title; Cookies. Expires.addhours (1); Context. RESPONSE.COOKIES.ADD (cookie); Bll. Updclicks (ID); Modify the number of hits in the data read to +1 dt. rows[0]["Clicknum"] = Convert.ToInt32 (dt. rows[0]["Clicknum"]) + 1; } else {//determines if the value of the cookie is the title of the current news, and if not, it has not been accessed, and the amount of clicks plus 1 if (cookie. ValuE! = title) {BLL. Updclicks (ID); Modify the number of hits in the data read to +1 dt. rows[0]["Clicknum"] = Convert.ToInt32 (dt. rows[0]["Clicknum"]) + 1; Cookies. Value = title; Context. RESPONSE.COOKIES.ADD (cookie); }} Res. state = Apistate.ok; Res. Data = DT; }

I mainly use a cookie way to achieve such a news click after the Count plus 1, this way is actually a certain bug, should be noted here is the user's most recent visit news headlines, then if the user in a few news between the switch, then still can not avoid malicious count!

. NET News click Changes to avoid malicious refreshes

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.