Exemplo n.º 1
0
        public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
        {
            var httpContext = context.HttpContext;
            //var action = actionContext.RouteData.Values["action"];
            //var controller = actionContext.RouteData.Values["controller"];
            var key = $"{httpContext.GetRemoteIpAddressToIPv4()}_{httpContext.Request.GetRequestUrlAddress()}";
            IDistributedCache cache = App.GetService <IDistributedCache>();

            if (cache.Exist(key))
            {
                context.Result = Provider.CreateResponse(new AvoidRepeatableRequestContext(httpContext, key));
                httpContext.Response.StatusCode = (int)HttpStatusCode.Forbidden;
            }
            else
            {
                cache.Set(key, 1, Seconds);
            }

            await next();
        }
Exemplo n.º 2
0
 public async Task <bool> Exist(string key)
 {
     return(await _cache.Exist(key));
 }