1. Background gets the validation byte stream, which is returned to the front end as a string.
Public actionresult getvalidategraphic () { varnew validatecode (); var code = Validate. Createvalidatecode (4); var image = Validate. Createvalidategraphic (code); session["validatecode"] = code; // return Content (convert.tobase64string (image)); }
2, the front desk with Ajax access
function () { $.ajax ({ false, "/login/getvalidategraphic", function (data) { $ (' #yxValidateCode '). attr (' src ', ' data:image/png;base64, ' + data); $ (' #bqfValidateCode '). attr (' src ', ' data:image/png;base64, ' + data); $ (' #glValidateCode '). attr (' src ', ' data:image/png;base64, ' + Data ');} ); }
This allows you to display multiple identical verification codes on the page.
So what is this? This is the data URI scheme. URI scheme is defined in RFC2397 to embed some small data directly into a Web page, eliminating the need to load it from an external file.
We can write images directly into an HTML file, which saves a picture request, and the downside is that the browser cannot cache the image.
Multiple verification codes need to be displayed on a single page of ASP.