public override void OnResultExecuting(ResultExecutionContext context)
		{
			if (_suppressResultFiltering)
				return;

			HttpResponseBase response = context.HttpContext.Response;
			context.HttpContext.Session.UpdateSessionId();

			_filter = response.Filter;
			response.Flush();

			response.Filter = new CaptureFilter(response.Filter);
		}
示例#2
0
        public override void OnResultExecuting(ResultExecutionContext context)
        {
            if (_suppressResultFiltering)
            {
                return;
            }

            HttpResponseBase response = context.HttpContext.Response;

            context.HttpContext.Session.UpdateSessionId();

            _filter = response.Filter;
            response.Flush();

            response.Filter = new CaptureFilter(response.Filter);
        }
        protected virtual ResultExecutedContext InvokeActionResultFilters(
            ControllerContext context, ICollection <IResultFilter> filters, ActionResult result)
        {
            Precondition.Require(context, () => Error.ArgumentNull("context"));
            Precondition.Require(result, () => Error.ArgumentNull("result"));
            Precondition.Require(filters, () => Error.ArgumentNull("filters"));

            ResultExecutionContext       rec          = new ResultExecutionContext(context, result);
            Func <ResultExecutedContext> continuation = () => {
                InvokeActionResult(context, result);
                return(new ResultExecutedContext(context, rec.Result, null));
            };

            Func <ResultExecutedContext> thunk = filters.Reverse().Aggregate(continuation,
                                                                             (next, filter) => () => InvokeActionResultFilter(filter, rec, next));

            return(thunk());
        }
        private static ResultExecutedContext InvokeActionResultFilter(IResultFilter filter,
                                                                      ResultExecutionContext context, Func <ResultExecutedContext> continuation)
        {
            filter.OnResultExecuting(context);

            if (context.Cancel)
            {
                return(new ResultExecutedContext(context, null));
            }

            bool wasError = false;
            ResultExecutedContext postContext = null;

            try
            {
                postContext = continuation();
            }
            catch (ThreadAbortException)
            {
                // This type of exception occurs as a result of Response.Redirect(), but we special-case so that
                // the filters don't see this as an error.
                postContext = new ResultExecutedContext(context, null);
                filter.OnResultExecuted(postContext);

                throw;
            }
            catch (Exception ex)
            {
                wasError    = true;
                postContext = new ResultExecutedContext(context, ex);
                filter.OnResultExecuted(postContext);

                if (!postContext.ExceptionHandled)
                {
                    throw;
                }
            }
            if (!wasError)
            {
                filter.OnResultExecuted(postContext);
            }

            return(postContext);
        }
		public virtual void OnResultExecuting(ResultExecutionContext context)
		{
		}
示例#6
0
 public virtual void OnResultExecuting(ResultExecutionContext context)
 {
 }
        protected virtual ResultExecutedContext InvokeActionResultFilters(
            ControllerContext context, ICollection<IResultFilter> filters, ActionResult result)
        {
            Precondition.Require(context, () => Error.ArgumentNull("context"));
            Precondition.Require(result, () => Error.ArgumentNull("result"));
            Precondition.Require(filters, () => Error.ArgumentNull("filters"));

            ResultExecutionContext rec = new ResultExecutionContext(context, result);
            Func<ResultExecutedContext> continuation = () => {
                InvokeActionResult(context, result);
                return new ResultExecutedContext(context, rec.Result, null);
            };

            Func<ResultExecutedContext> thunk = filters.Reverse().Aggregate(continuation,
                (next, filter) => () => InvokeActionResultFilter(filter, rec, next));
            return thunk();
        }
        private static ResultExecutedContext InvokeActionResultFilter(IResultFilter filter, 
            ResultExecutionContext context, Func<ResultExecutedContext> continuation)
        {
            filter.OnResultExecuting(context);

            if (context.Cancel)
                return new ResultExecutedContext(context, null);

            bool wasError = false;
            ResultExecutedContext postContext = null;
            try
            {
                postContext = continuation();
            }
            catch (ThreadAbortException)
            {
                // This type of exception occurs as a result of Response.Redirect(), but we special-case so that
                // the filters don't see this as an error.
                postContext = new ResultExecutedContext(context, null);
                filter.OnResultExecuted(postContext);

                throw;
            }
            catch (Exception ex)
            {
                wasError = true;
                postContext = new ResultExecutedContext(context, ex);
                filter.OnResultExecuted(postContext);
                
                if (!postContext.ExceptionHandled)
                    throw;
            }
            if (!wasError)
                filter.OnResultExecuted(postContext);
            
            return postContext;
        }
示例#9
0
 /// <summary>
 /// Method called before the action result returned by an action method is executed.
 /// </summary>
 /// <param name="context">Contains information about the current request and action result</param>
 protected virtual void OnPreResult(ResultExecutionContext context)
 {
 }
示例#10
0
 void IResultFilter.OnResultExecuting(ResultExecutionContext context)
 {
     OnPreResult(context);
 }