mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
#18663: Custom errors should not shorcut HandleErrorAttribute
Work Item: 18663 --HG-- branch : 1.x
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Web;
|
using System.Web;
|
||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
@@ -30,34 +31,38 @@ namespace Orchard.Exceptions.Filters {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void OnActionExecuted(ActionExecutedContext filterContext) {
|
public void OnActionExecuted(ActionExecutedContext filterContext) {
|
||||||
if (!filterContext.ExceptionHandled && filterContext.Exception != null) {
|
|
||||||
if (_exceptionPolicy.HandleException(this, filterContext.Exception)) {
|
|
||||||
var shape = _orchardServices.New.ErrorPage();
|
|
||||||
shape.Message = filterContext.Exception.Message;
|
|
||||||
shape.Exception = filterContext.Exception;
|
|
||||||
|
|
||||||
filterContext.ExceptionHandled = true;
|
// don't provide custom errors if the action has some custom code to handle exceptions
|
||||||
|
if(!filterContext.ActionDescriptor.GetCustomAttributes(typeof(HandleErrorAttribute), false).Any()) {
|
||||||
|
if (!filterContext.ExceptionHandled && filterContext.Exception != null) {
|
||||||
|
if (_exceptionPolicy.HandleException(this, filterContext.Exception)) {
|
||||||
|
var shape = _orchardServices.New.ErrorPage();
|
||||||
|
shape.Message = filterContext.Exception.Message;
|
||||||
|
shape.Exception = filterContext.Exception;
|
||||||
|
|
||||||
// inform exception filters of the exception that was suppressed
|
filterContext.ExceptionHandled = true;
|
||||||
var filterInfo = new FilterInfo();
|
|
||||||
foreach (var filterProvider in _filterProviders.Value) {
|
|
||||||
filterProvider.AddFilters(filterInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
var exceptionContext = new ExceptionContext(filterContext.Controller.ControllerContext, filterContext.Exception);
|
// inform exception filters of the exception that was suppressed
|
||||||
foreach (var exceptionFilter in filterInfo.ExceptionFilters) {
|
var filterInfo = new FilterInfo();
|
||||||
exceptionFilter.OnException(exceptionContext);
|
foreach (var filterProvider in _filterProviders.Value) {
|
||||||
}
|
filterProvider.AddFilters(filterInfo);
|
||||||
|
}
|
||||||
|
|
||||||
if (exceptionContext.ExceptionHandled) {
|
var exceptionContext = new ExceptionContext(filterContext.Controller.ControllerContext, filterContext.Exception);
|
||||||
filterContext.Result = exceptionContext.Result;
|
foreach (var exceptionFilter in filterInfo.ExceptionFilters) {
|
||||||
}
|
exceptionFilter.OnException(exceptionContext);
|
||||||
else {
|
}
|
||||||
filterContext.Result = new ShapeResult(filterContext.Controller, shape);
|
|
||||||
filterContext.RequestContext.HttpContext.Response.StatusCode = 500;
|
|
||||||
|
|
||||||
// prevent IIS 7.0 classic mode from handling the 404/500 itself
|
if (exceptionContext.ExceptionHandled) {
|
||||||
filterContext.RequestContext.HttpContext.Response.TrySkipIisCustomErrors = true;
|
filterContext.Result = exceptionContext.Result;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
filterContext.Result = new ShapeResult(filterContext.Controller, shape);
|
||||||
|
filterContext.RequestContext.HttpContext.Response.StatusCode = 500;
|
||||||
|
|
||||||
|
// prevent IIS 7.0 classic mode from handling the 404/500 itself
|
||||||
|
filterContext.RequestContext.HttpContext.Response.TrySkipIisCustomErrors = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user