public override void OnActionExecuting(ActionExecutingContext filterContext) { BrandcaptchaValidator validator = new BrandcaptchaValidator(); validator.PrivateKey = BrandcaptchaControlMvc.PrivateKey; validator.RemoteIP = filterContext.HttpContext.Request.UserHostAddress; validator.Challenge = filterContext.HttpContext.Request.Form[CHALLENGE_FIELD_KEY]; validator.Response = filterContext.HttpContext.Request.Form[RESPONSE_FIELD_KEY]; validator.Proxy = proxy; if (string.IsNullOrEmpty(validator.Challenge)) { this._brandcaptchaResponse = BrandcaptchaResponse.InvalidChallenge; } else if (string.IsNullOrEmpty(validator.Response)) { this._brandcaptchaResponse = BrandcaptchaResponse.InvalidResponse; } else { this._brandcaptchaResponse = validator.Validate(); } // this will push the result values into a parameter in our Action filterContext.ActionParameters["captchaValid"] = this._brandcaptchaResponse.IsValid; filterContext.ActionParameters["captchaErrorMessage"] = this._brandcaptchaResponse.ErrorMessage; base.OnActionExecuting(filterContext); }
/// <summary> /// Perform validation of Brancaptcha. /// </summary> public void Validate() { if (Page.IsPostBack && Visible && Enabled) { if (this._brandcaptchaResponse == null) { if (Visible && Enabled) { BrandcaptchaValidator validator = new BrandcaptchaValidator(); validator.PrivateKey = this.PrivateKey; validator.RemoteIP = Page.Request.UserHostAddress; validator.Challenge = Context.Request.Form[BRANDCAPTCHA_CHALLENGE_FIELD]; validator.Response = Context.Request.Form[BRANDCAPTCHA_RESPONSE_FIELD]; validator.Proxy = this.proxy; if (validator.Challenge == null) { this._brandcaptchaResponse = BrandcaptchaResponse.InvalidChallenge; } else if (validator.Response == null) { this._brandcaptchaResponse = BrandcaptchaResponse.InvalidResponse; } else { this._brandcaptchaResponse = validator.Validate(); } } } } else { this._brandcaptchaResponse = BrandcaptchaResponse.Valid; } }