jQuery的剑道UI免费下载30天试用版

验证码设置

本文解释了如何使用应用程序的后端来验证用户对Kendo UI Captcha的响应。

始终生成Captcha并在应用程序的服务器端应用验证。这种方法保证没有程序或机器人可以通过JavaScript在客户端访问Captcha的值,然后绕过验证。

要继续下面的教程,请确保验证码服务器端提供程序在项目中添加并引用。

开始

为了生成验证码并验证用户的输入,剑道UI验证码依赖于以下主要选项:

  • 处理程序-设置获取生成图像的URL处理程序、函数或操作配置。
  • AudioHandler-设置获取生成音频的URL处理程序、函数或动作配置。
  • ValidationHandler-设置URL处理程序、函数或操作配置,可以远程验证captcha。

  1. 要生成新的验证码,请使用GetNewCaptcha ()方法CaptchaHelper。将验证码保存到会话。

    public ActionResult Reset() {CaptchaImage newCaptcha = CaptchaHelper.GetNewCaptcha();会话["captcha" +新captcha。UniqueId] = newCaptcha;返回Json(new {captcha = Url。Action("image", "captcha", new {captchaId = newCaptcha。UniqueId}), captchaId = newCaptcha。, JsonRequestBehavior.AllowGet);}公共ActionResult Image(string captchaId) {CaptchaImage captcha = (CaptchaImage)Session["captcha" + captchaId];var image = CaptchaHelper.RenderCaptcha(captcha);byte [] bmpBytes;使用(MemoryStream ms = new MemoryStream()){图像。保存(女士,ImageFormat.Png);bmpBytes = ms.ToArray(); } return File(bmpBytes, "image/png"); }
  2. 介绍jQuery验证码的剑道UI:

     
  3. 添加验证码的服务器端验证处理程序:

    public ActionResult Validate(CaptchaModel model) {string text = GetCaptchaText(model. captchaid);返回Json(text == model.Captcha.ToUpperInvariant());}

    形式的集成

有关在表单中集成Captcha的完整示例,请查看概述演示

另请参阅

在本文中
Baidu
map