ASP. NET: The image cannot be displayed when the Session verification code is saved in a general processing program ?,
Using System. Drawing;
Using System. Web;
Using System. Web. SessionState;
/// <Summary>
/// CaptchaHandler Summary
/// </Summary>
Public class CaptchaHandler: IHttpHandler, IRequiresSessionState
{
Public void ProcessRequest (HttpContext context)
{
// GDI + three steps 1 canvas 2 create a paint brush for the canvas 3 draw the required material
Var vCode = CaptchaHelper. CreateRandomCode (5); // self-encapsulated Extension Method
Var buffer = CaptchaHelper. DrawImage (vCode, background: Color. White); // self-encapsulated Extension Method
Context. Session ["vCode"] = vCode; // vCode: string-type verification code string
Context. Response. ContentType = "image/gif ";
Context. Response. BinaryWrite (buffer );
}
Public bool IsReusable {get {return false ;}}
}
[Key] Handler needs to implement the IRequiresSessionState interface (The namespace using System. Web. SessionState ;)