/// <summary>
        /// 获取验证码
        /// </summary>
        /// <returns></returns>
        public ActionResult GetCaptchaCode()
        {
            CaptchaCode code = new CaptchaCode();

            if (Session["CaptchaCode"] == null)
            {
                Session.Add("CaptchaCode", code.Text);
            }
            else
            {
                Session["CaptchaCode"] = code.Text;
            }
            return(File(code.RenderImage(), @"image/jpeg"));
        }
Beispiel #2
0
        private static MvcHtmlString GetCaptchaCode(this HtmlHelper helper, string actionName, string controllerName, CaptchaOptions options)
        {
            if (options == null)
            {
                options = new CaptchaOptions();
            }
            var image = new CaptchaCode(options);

            HttpContext.Current.Session.Add(
                "CaptchaCode",
                image);
            var          url           = new UrlHelper(helper.ViewContext.RequestContext);
            var          sb            = new StringBuilder(1500);
            const string copyrightText = "\r\n<!-- MyCaptcha 1.0 @Leiyang -->\r\n";

            sb.Append(copyrightText);
            sb.Append(CreateImgTag(options));
            sb.Append(copyrightText);
            return(MvcHtmlString.Create(sb.ToString()));
        }