首页 > 网站 > 建站经验 > 正文

asp.n et网站防恶意刷新的Cookies与Session解决方法

2019-11-02 14:53:12
字体:
来源:转载
供稿:网友

 本文实例讲述了asp.net网站防恶意刷新的Cookies与Session解决方法,是WEB程序设计中非常实用的技巧。分享给大家供大家参考。具体实现方法如下:

Session版实现方法:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 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(); }
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表