public Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) { var reason = ModelSanitizer.Sanitize(context.HttpContext.Request.Query["reason"].ToString()); if (reason != null && reason.Length >= MinReasonLength) { return(next()); } context.Result = ResultUtilities.BadRequest("A valid reason must be provided for this action."); return(Task.CompletedTask); }
public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next) { var validator = context.HttpContext.RequestServices.GetService <IRecaptchaValidator>(); var value = ModelSanitizer.Sanitize(context.HttpContext.Request.Query["recaptcha"].ToString()); if (await validator.TryValidateAsync(value, context.HttpContext.RequestAborted)) { await next(); } else { context.Result = ResultUtilities.BadRequest("Could not verify reCAPTCHA token."); } }