JS Refresh Verification Code (. NET)

Source: Internet
Author: User


JS Refresh Verification Code:

<a href= "javascript:changeimg ();" Style= "color:red; font-size:12px; Text-decoration:none, "title=" can't see clearly? Click to change "> </a>


Refresh Verification Code

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>    ///  handler for verification code     ///  when the handler is called, the parameter type is added to indicate which function requires the verification code     ///  The sessionkey that gets the verification code is 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 processrequest (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 =  "Image/png" ;             response.binarywrite (bytes);         }        public bool  IsReusable        {             get            {                 return  false;            }         }    }}


Write the value of the parameter as a random number
So every time I click Refresh,
The cache is different.
It's going to be a refreshing effect.

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/74/AA/wKiom1YlrUujatZjAAGfZLm3Ar4391.jpg "title=" aa.png "alt=" Wkiom1ylruujatzjaagfzlm3ar4391.jpg "/>

This article is from the "Wennuanyiran" blog, make sure to keep this source http://dingzhaoqiang.blog.51cto.com/5601059/1704443

JS Refresh Verification Code (. NET)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.