Exemple #1
0
        /// <summary>
        /// Invoke the middleware
        /// </summary>
        /// <param name="context">The current context</param>
        /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
        public async Task Invoke(HttpContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (_mustGenerateNonce)
            {
                context.SetNonce(_nonceGenerator.GetNonce(Constants.DefaultBytesInNonce));
            }

            context.Response.OnStarting(() =>
            {
                var result = _service.EvaluatePolicy(context, _policy);
                _service.ApplyResult(context.Response, result);
#if NET451
                return(Task.FromResult(true));
#else
                return(Task.CompletedTask);
#endif
            });

            await _next(context);
        }
Exemple #2
0
        /// <summary>
        /// Invoke the middleware
        /// </summary>
        /// <param name="context">The current context</param>
        /// <returns></returns>
        public async Task Invoke(HttpContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var policy = _policy ?? await _policyProvider.GetPolicyAsync(context, _policyName);

            if (policy != null)
            {
                var result = _service.EvaluatePolicy(context, policy);
                _service.ApplyResult(context.Response, result);
            }

            await _next(context);
        }
Exemple #3
0
        /// <summary>
        /// Invoke the middleware
        /// </summary>
        /// <param name="context">The current context</param>
        /// <returns></returns>
        public async Task Invoke(HttpContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            context.Response.OnStarting(() =>
            {
                var result = _service.EvaluatePolicy(context, _policy);
                _service.ApplyResult(context.Response, result);
#if NET451
                return(Task.FromResult(true));
#else
                return(Task.CompletedTask);
#endif
            });

            await _next(context);
        }