Exemplo n.º 1
0
        public override void OnAuthorization(HttpActionContext context)
        {
            var customer = ECommerceContext.CurrentCustomer;

            if (customer != null)
            {
                return;
            }

            context.Response = FilterHelper.ErrorResponse("Unauthorized access");
        }
Exemplo n.º 2
0
 public override void OnAuthorization(HttpActionContext context)
 {
     if (context.Request.RequestUri.Scheme != Uri.UriSchemeHttps)
     {
         context.Response = FilterHelper.ErrorResponse("HTTPS required");
     }
     else
     {
         base.OnAuthorization(context);
     }
 }
        public override void OnActionExecuting(HttpActionContext context)
        {
            var queryString = context.Request.GetQueryNameValuePairs();

            if (queryString.Any(q => q.Key == ParameterName))
            {
                return;
            }

            context.Response = FilterHelper.ErrorResponse($"Request validation error : Missing query parameter {ParameterName}");
        }
Exemplo n.º 4
0
        public override void OnActionExecuting(HttpActionContext context)
        {
            if (!context.ModelState.IsValid)
            {
                var message = context.ModelState.Values?.FirstOrDefault(v => (v.Errors?.Count ?? 0) > 0)?.Errors?.FirstOrDefault()?.ErrorMessage;

                if (string.IsNullOrEmpty(message))
                {
                    message = "Bad request format";
                }

                context.Response = FilterHelper.ErrorResponse($"Request validation error : {message}");
            }
        }
Exemplo n.º 5
0
        public override void OnException(HttpActionExecutedContext context)
        {
            context.Response = FilterHelper.ErrorResponse(context.Exception.Message);

            logger?.LogException(loggerSource, context.Exception);
        }