private void CreateYZM(HttpContext context) { // 在此处放置用户代码以初始化页面 context.Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache); //不缓存 Common.YZMHelper yz = new Common.YZMHelper(); context.Session["validcode"] = yz.Text; //将验证字符写入Session,供前台调用 MemoryStream ms = new MemoryStream(); yz.Image.Save(ms, System.Drawing.Imaging.ImageFormat.Gif); yz.Image.Dispose(); context.Response.ClearContent(); context.Response.ContentType = "image/Gif"; context.Response.BinaryWrite(ms.ToArray()); }
//获取验证码 public void VerifyChars() { Response.ContentType = "image/Png"; // 在此处放置用户代码以初始化页面 Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache); //不缓存 Common.YZMHelper yz = new Common.YZMHelper(); yz.CreateImage(); Session["checkcode"] = yz.Text; //将验证字符写入Session,供前台调用 MemoryStream ms = new MemoryStream(); yz.Image.Save(ms, ImageFormat.Png); //Response.ClearContent(); //需要输出图象信息 要修改HTTP头 Response.BinaryWrite(ms.ToArray()); yz.Image.Dispose(); //Response.End(); //return ms.ToArray(); }