/// <summary> /// 登录验证码 /// </summary> public void VerifyCode_GET() { string word = null; VerifyCode v = new VerifyCode(); var font = v.GetDefaultFont(); try { font = new System.Drawing.Font(font.FontFamily, 16); v.AllowRepeat = false; Response.BinaryWrite(v.GraphicDrawImage(4, VerifyWordOptions.Letter, !true, font, 60, out word)); VerifyCodeManager.AddWord(word); Response.ContentType = "Image/Jpeg"; } catch (Exception exc) { if (font != null) { font.Dispose(); } throw exc; } }
public void VerifyImg(string length, string opt, string usefor) { int _length; //验证码长度 VerifyWordOptions _opt; //验证码选项 string verifycode; //验证码 if (String.IsNullOrEmpty(length) || !Regex.IsMatch(length, "^\\d+$")) { _length = 4; } else { _length = int.Parse(length); } if (String.IsNullOrEmpty(opt) || !Regex.IsMatch(opt, "^\\d$")) { _opt = VerifyWordOptions.Number; } else { _opt = (VerifyWordOptions)int.Parse(opt); } VerifyCode v = new VerifyCode(); v.AllowRepeat = false; //显示验证码 v.RenderGraphicImage(_length, _opt, true, out verifycode, "Image/Jpeg"); //保存验证码 Session[String.Format("$cms.site_{0}_verifycode", this.OutputCntext.CurrentSite.SiteId.ToString())] = verifycode; }
/// <summary> /// 验证码 /// </summary> /// <param name="context"></param> public void VerifyCode(HttpContext context) { string word = null; VerifyCode v = new VerifyCode(); var font = v.GetDefaultFont(); try { font = new System.Drawing.Font(font.FontFamily, 16); v.AllowRepeat = false; context.Response.BinaryWrite(v.GraphicDrawImage(4, VerifyWordOptions.Number, !true, font, 30, out word)); } catch { if (font != null) { font.Dispose(); } } context.Response.ContentType = "Image/Jpeg"; VerifyCodeManager.AddWord(word); }