您好,登錄后才能下訂單哦!
這篇文章主要講解了“asp.net網(wǎng)站防惡意刷新的Cookies與Session如何解決”,文中的講解內(nèi)容簡單清晰,易于學習與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學習“asp.net網(wǎng)站防惡意刷新的Cookies與Session如何解決”吧!
Session版實現(xiàn)方法:
public double time; public const int freetime = 1;//防刷冰凍時間間隔,當前為1秒 #region 防惡意刷新 if (Session.SessionID == null) { Response.End(); } else if (Session["sionid"] == null) { Session["sionid"] = Session.SessionID; } if (Session["last"] == null) { Session["last"] = DateTime.Now; } else { DateTime thisTime = DateTime.Now; DateTime lastTime = DateTime.Parse(Session["last"].ToString()); if (Session.SessionID == Session["sionid"].ToString()) Session["last"] = thisTime; TimeSpan ts = thisTime - lastTime; time = ts.TotalMilliseconds; if (time < freetime * 500) { warm_prompt(); } } #endregion public void warm_prompt() { Response.Write("<table width='778' border='0' align='center' cellpadding='3' cellspacing='2' bgcolor='#009900' style='font-size: 14px; '>"); Response.Write(" <tr bgcolor='#FFFFFF'>"); Response.Write(" <td><img src='/newimages/logos.gif'></td>"); Response.Write(" <td bgcolor='#EEFFEE'為了保證您的訪問安全,請您 " + freetime + " 秒后<a href='" + Request.RawUrl + "' target='_self' style='color:#FF0000;'>點擊這里刷新</a>此頁面</td>"); Response.Write(" </tr>"); Response.Write("</table>"); Response.End(); }
Cookies版實現(xiàn)方法:
public double time; public const int freetime = 2; #region 防惡意刷新 string page; if (Request.Cookies["page"] == null) { page = ""; } else { page = HttpContext.Current.Request.Cookies["page"].Value.ToString(); //獲取cookie中存儲的url值 } string strThisPage = HttpContext.Current.Request.Url.PathAndQuery.ToString();//獲取當前頁地址 DateTime LastTime = DateTime.Now; if (page.Equals(strThisPage))//如果cookie中的值和當前頁相等,那么表示是刷新操作 { TimeSpan ts = LastTime - DateTime.Parse(HttpContext.Current.Request.Cookies["time"].Value.ToString()); time = ts.Seconds; if (time < freetime) { warm_prompt(); } } else { //執(zhí)行操作 Response.Cookies["page"].Value = strThisPage; Response.Cookies["time"].Value = LastTime.ToString(); } #endregion public void warm_prompt() { Response.Write("<table width='778' border='0' align='center' cellpadding='3' cellspacing='2' bgcolor='#009900' style='font-size: 14px; '>"); Response.Write(" <tr bgcolor='#FFFFFF'>"); Response.Write(" <td><img src='/newimages/logos.gif'></td>"); Response.Write(" <td bgcolor='#EEFFEE'為了保證您的訪問安全,頁面將在2秒后將自動跳轉(zhuǎn)到您要訪問的內(nèi)容!</td>"); Response.Write(" </tr>"); Response.Write("</table>"); Response.Write("<meta http-equiv=\"refresh\" content=\"2\";URL=" + HttpContext.Current.Request.Cookies["page"].Value.ToString() + ">"); Response.End(); }
感謝各位的閱讀,以上就是“asp.net網(wǎng)站防惡意刷新的Cookies與Session如何解決”的內(nèi)容了,經(jīng)過本文的學習后,相信大家對asp.net網(wǎng)站防惡意刷新的Cookies與Session如何解決這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是億速云,小編將為大家推送更多相關知識點的文章,歡迎關注!
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內(nèi)容。