Пример #1
0
        /// <summary>
        /// 生成验证码图片
        /// </summary>
        /// <returns></returns>
        public ActionResult validcode()
        {
            string strRandon = Common.ValidCodeUtils.GetRandomCode(4); //生成一个随机字符串 验证码

            Session["validcode"] = strRandon;                          //将验证码放入Session
            byte[] robyty = ValidCodeUtils.CreateImage(strRandon);     //byte[] 根据验证码生成图片
            return(File(robyty, @"image/jpeg"));
        }
Пример #2
0
        public ActionResult CreateValidCodeImage()
        {
            //生成长度为5的随机验证码字符串
            var strRandom = ValidCodeUtils.GetRandomCode(5);

            //根据生成的验证码字符串生成图片
            byte[] byteImg = ValidCodeUtils.CreateImage(strRandom);
            //将验证码字符串存入sessiona
            //ViewData["validCode"] = strRandom;
            HttpContext.Session.SetString("validCode", strRandom);
            //把图片返回视图
            return(File(byteImg, @"image/jepg"));
        }