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