You can use it, but if you check that the operations were done twice or more, you change your perspective from anti-fake to spam. Twice or more actions can be classified as spam events. If you want to prevent this situation, you must write code, for example:
public class PreventSpamAttribute : ActionFilterAttribute
{
public int DelayRequest = 10;
public string ErrorMessage = "Excessive Request Attempts Detected.";
public string ErrorResouceKey = string.Empty;
public string RedirectUrl;
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
var request = filterContext.HttpContext.Request;
var cache = filterContext.HttpContext.Cache;
var originationInfo = request.ServerVariables["HTTP_X_FORWARDED_FOR"] ?? request.UserHostAddress;
originationInfo += request.UserAgent;
var targetInfo = request.RawUrl + request.QueryString;
var hashValue = string.Join("", MD5.Create().ComputeHash(Encoding.ASCII.GetBytes(originationInfo + targetInfo)).Select(s => s.ToString("x2")));
if (cache[hashValue] != null)
{
}
cache.Add(hashValue, 1, null, DateTime.Now.AddSeconds(DelayRequest), Cache.NoSlidingExpiration, CacheItemPriority.Default, null);
base.OnActionExecuting(filterContext);
}
}
When using (you can change the error handling strategy);
[PreventSpam(DelayRequest = 5, ErrorMessage = "Please try again in 5 seconds.")]
public virtual JsonResult Login()
{
}
source
share