您好,登錄后才能下訂單哦!
js刷新驗證碼:
<a href="javascript:changeImg();" title="看不清?點擊換一張"> <img id="imgcode" src="Handler/CheckCodeHandler.ashx?type=login&stamp=1" width="80" height="30" onclick="changeUrl()"/> </a>
//刷新驗證碼
function changeImg() { document.getElementById("imgcode").src = "Handler/CheckCodeHandler.ashx?type=login&stamp=" + Math.random(); }
CheckCodeHandler.ashx
using System; using System.Web; namespace YK.WebSite.Handler { /// <summary> /// 用于驗證碼的處理程序 /// 調用該處理程序時,要加參數type,表明是哪一個功能需要的驗證碼 /// 獲取驗證碼的SessionKey是YK.Website.CheckCode.[type] /// </summary> public class CheckCodeHandler : IHttpHandler { public HttpResponse Response { get { return HttpContext.Current.Response; } } public HttpRequest Request { get { return HttpContext.Current.Request; } } public void Proce***equest(HttpContext context) { string type = Request.QueryString["type"]; if (String.IsNullOrWhiteSpace(type)) return; Response.Buffer = true; Response.ExpiresAbsolute = System.DateTime.Now.AddMilliseconds(0); Response.Expires = 0; Response.CacheControl = "no-cache"; Response.AppendHeader("Pragma", "No-Cache"); string chkCode = String.Empty; byte[] bytes = YK.Common.Util.CheckCodeKit.GetChkCodeBytes(ref chkCode); YK.Core.Context.Context.SetDataBySession("YK.Website.CheckCode." + type, chkCode); Response.ClearContent(); Response.ContentType = "p_w_picpath/Png"; Response.BinaryWrite(bytes); } public bool IsReusable { get { return false; } } } }
把參數的值寫成隨機數
這樣每次點擊刷新的時候
緩存就不一樣了
就可以起到刷新的效果了
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。