Beispiel #1
0
        public void OnException(ExceptionContext context)
        {
            Precondition.Require(context, () => Error.ArgumentNull("context"));
            Controller controller = (context.Controller as Controller);

            if (controller == null || context.Handled || !context.Context.IsCustomErrorEnabled)
            {
                return;
            }

            Exception exception = context.Exception;

            if (new HttpException(null, exception).GetHttpCode() != 500)
            {
                return;
            }

            if (exception is TargetInvocationException)
            {
                exception = exception.InnerException;
            }

            if (!_type.IsInstanceOfType(exception))
            {
                return;
            }

            ErrorHandlerInfo model = new ErrorHandlerInfo(context.Exception);

            context.Handled = true;
            context.Context.Response.Clear();

            if (!context.IsChild)
            {
                context.Context.Response.StatusCode = 500;
            }

            if (String.IsNullOrEmpty(_view))
            {
                context.Result = EmptyResult.Instance;
            }
            else
            {
                context.Result = new ViewResult()
                {
                    TempData = controller.TempData,
                    ViewData = new ViewDataDictionary <ErrorHandlerInfo>(model),
                    ViewName = View
                }
            };
        }

        #endregion
    }
        public void OnException(ExceptionContext context)
        {
            Precondition.Require(context, () => Error.ArgumentNull("context"));
            Controller controller = (context.Controller as Controller);
            if (controller == null || context.Handled || !context.Context.IsCustomErrorEnabled)
                return;

            Exception exception = context.Exception;
            if (new HttpException(null, exception).GetHttpCode() != 500)
                return;

            if (exception is TargetInvocationException)
                exception = exception.InnerException;

            if (!_type.IsInstanceOfType(exception))
                return;
            
            ErrorHandlerInfo model = new ErrorHandlerInfo(context.Exception);
            context.Handled = true;
            context.Context.Response.Clear();

			if(!context.IsChild)
				context.Context.Response.StatusCode = 500;

            if (String.IsNullOrEmpty(_view))
                context.Result = EmptyResult.Instance;
            else
                context.Result = new ViewResult() {
                    TempData = controller.TempData,
                    ViewData = new ViewDataDictionary<ErrorHandlerInfo>(model), 
                    ViewName = View 
				};
        }