Ejemplo n.º 1
0
        public async Task <bool> OnAuthorization(HttpContext context, HttpServerMessageSender sender, string messageId, IEnumerable <IAuthorizationFilter> filters)
        {
            foreach (var filter in filters)
            {
                var path         = HttpUtility.UrlDecode(GetRoutePath(context.Request.Path.ToString()));
                var serviceRoute = await _serviceRouteProvider.GetRouteByPathRegex(path);

                if (serviceRoute == null)
                {
                    serviceRoute = await _serviceRouteProvider.GetLocalRouteByPathRegex(path);
                }
                //RestContext.GetContext().SetAttachment("route", serviceRoute);
                var filterContext = new AuthorizationFilterContext
                {
                    Path    = path,
                    Context = context,
                    Route   = serviceRoute
                };
                await filter.OnAuthorization(filterContext);

                if (filterContext.Result != null)
                {
                    await sender.SendAndFlushAsync(new TransportMessage(messageId, filterContext.Result));

                    return(false);
                }
            }
            return(true);
        }
Ejemplo n.º 2
0
        public async Task <bool> OnException(HttpContext context, HttpServerMessageSender sender, string messageId, Exception exception, IEnumerable <IExceptionFilter> filters)
        {
            foreach (var filter in filters)
            {
                var path          = HttpUtility.UrlDecode(GetRoutePath(context.Request.Path.ToString()));
                var filterContext = new ExceptionContext
                {
                    RoutePath = path,
                    Context   = context,
                    Exception = exception
                };
                await filter.OnException(filterContext);

                if (filterContext.Result != null)
                {
                    await sender.SendAndFlushAsync(new TransportMessage(messageId, filterContext.Result));

                    return(false);
                }
            }
            return(true);
        }