Revision: 15943
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at July 21, 2009 09:56 by RockinForGod
Initial Code
public class ValidateAntiSpamAttribute : ActionFilterAttribute { public string ErrorMessage { get; set; } public ValidateAntiSpamAttribute() { } public ValidateAntiSpamAttribute(string errorMessage) { this.ErrorMessage = errorMessage; } public override void OnActionExecuting(ActionExecutingContext filterContext) { string sixtimesnine = (string)filterContext.HttpContext.Request.Form["sixtimesnine"]; string fourtytwo = (string)filterContext.HttpContext.Request.Form["fourtytwo"]; if (string.IsNullOrEmpty(sixtimesnine) || string.IsNullOrEmpty(fourtytwo) || sixtimesnine != fourtytwo) { filterContext.Controller.ViewData.ModelState.AddModelError("Spam", this.ErrorMessage); } else { // Merely for unit testing puproses - we need to make sure that the above clause // was *not* run. filterContext.Controller.ViewData["filter"] = "passed"; } base.OnActionExecuting(filterContext); } }
Initial URL
Initial Description
Initial Title
ASP.NET MVC - ValidateAntiSpamAtrribute
Initial Tags
Initial Language
C#