Exemplo n.º 1
0
 /// <summary>
 /// 返回验证码
 /// </summary>
 /// <returns></returns>
 public ActionResult GetValidateCode()
 {
     ValidateCode vCode = new ValidateCode();
     string code = vCode.CreateValidateCode(5);
     Session["ValidateCode"] = code;
     byte[] bytes = vCode.CreateValidateGraphic(code);
     return File(bytes, @"image/jpeg");
 }
Exemplo n.º 2
0
    {//                                  #### #一般处理程序中如果要用session,必须条件上边这个接口
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            Common.ValidateCode vc = new Common.ValidateCode();
            string code            = vc.CreateValidateCode(4);

            context.Session["code"] = code;//#### #
            vc.CreateValidateGraphic(code, context);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 展示验证码并将验证码中的字符串保存至Session中
        /// </summary>
        /// <returns></returns>
        public ActionResult ValidateCode()
        {
            //1 创建自定义验证码类
            Common.ValidateCode validateCode = new Common.ValidateCode();
            //2 调用该类中的创建验证码的方法,给我们返回验证码对应的字符串(4个数字)
            string code = validateCode.CreateValidateCode(4);//创建长度为4个字母的图片

            Session["validateCode"] = code; //将验证码保存至Session(未保存至分布式缓存)

            byte[] buffer = validateCode.CreateValidateGraphic(code);
            return File(buffer, "imge.jpg");
        }