Using System.Drawing;
Using System.Web;
Using System.Web.SessionState;
<summary>
Summary description of Captchahandler
</summary>
public class Captchahandler:ihttphandler, IRequiresSessionState
{
public void ProcessRequest (HttpContext context)
{
GDI + three Step 1 Canvas 2 Create a brush for the canvas 3 draw the required footage
var vcode = Captchahelper.createrandomcode (5); Self-encapsulated extension methods
var buffer = Captchahelper.drawimage (Vcode, background:Color.White); Self-encapsulated extension methods
Context. session["Vcode"] = Vcode;
Context. Response.ContentType = "Image/gif";
Context. Response.BinaryWrite (buffer);
}
public bool IsReusable {get {return false;}}
}
"Critical" Handler to implement the IRequiresSessionState interface (where the namespace using System.Web.SessionState;)
Want to save the verification code in a generic handler by the Session and not display the picture?