예제 #1
0
        /// <summary>
        /// Called when [authorization].
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="sender">The sender.</param>
        /// <param name="messageId">The message identifier.</param>
        /// <param name="filters">The filters.</param>
        /// <returns>Task&lt;System.Boolean&gt;.</returns>
        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);
                }
                context.Items.Add("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);
        }
예제 #2
0
        /// <summary>
        /// Called when [exception].
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="sender">The sender.</param>
        /// <param name="messageId">The message identifier.</param>
        /// <param name="exception">The exception.</param>
        /// <param name="filters">The filters.</param>
        /// <returns>Task&lt;System.Boolean&gt;.</returns>
        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);
        }