色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

asp.net網(wǎng)站防惡意刷新的Cookies與Session解決方法

本文實例講述了ASP.NET網(wǎng)站防惡意刷新的Cookies與Session解決方法,是WEB程序設(shè)計中非常實用的技巧。分享給大家供大家參考。具體實現(xiàn)方法如下:

Session版實現(xiàn)方法:

public double time;public const int freetime = 1;//防刷冰凍時間間隔,當(dāng)前為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();  }}#endregionpublic 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();//獲取當(dāng)前頁地址 DateTime LastTime = DateTime.Now;if (page.Equals(strThisPage))//如果cookie中的值和當(dāng)前頁相等,那么表示是刷新操作 {  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();}#endregionpublic 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程序設(shè)計有一定的借鑒價值。

AspNet技術(shù)asp.net網(wǎng)站防惡意刷新的Cookies與Session解決方法,轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 安泽县| 清河县| 乐亭县| 彰武县| 鄢陵县| 中方县| 砚山县| 西青区| 澄江县| 呈贡县| 分宜县| 沽源县| 安化县| 印江| 明星| 永定县| 祁阳县| 蒲城县| 汝州市| 称多县| 卢湾区| 沭阳县| 曲阳县| 邯郸市| 宜兰县| 岳阳市| 镇巴县| 绥棱县| 建湖县| 泸州市| 洛阳市| 什邡市| 河北区| 临高县| 行唐县| 汉沽区| 山阴县| 柯坪县| 航空| 方正县| 宁国市|