未处理的exception未被Global.asaxerror handling程序或自定义IHttpModuleerror handling程序捕获

我有一个类(DPCal_EventMove)的方法,我想限制使用角色的访问。 我有一个Global.asax.cserror handling程序和一个自定义IHttpModuleerror handling程序,用于捕获未处理的exception和Server.Transfer他们GlobalExceptionHandler.aspx,它检查错误是否是源自失败的PrincipalPermission检查的SecurityExceptions。 由于某种原因,由PricipalPermission修饰方法引起的未处理exception不会通过我的任何error handling程序进行路由。 我的问题是:这个exception被路由到哪里以及如何捕获和处理它?

public partial class DayView : Page { protected void Page_Load(object sender, EventArgs e) { // Do some stuff } [PrincipalPermission(SecurityAction.Demand, Role = "Investigator")] [PrincipalPermission(SecurityAction.Demand, Role = "Administrator")] protected void DPCal_EventMove(object sender, DayPilot.Web.Ui.Events.EventMoveEventArgs e) { // If no overlap, then save int eventId = Convert.ToInt32(e.Value); MembershipUser user = Membership.GetUser(); if (!CommonFunctions.IsSchedulingConflict(eventId, e.NewStart, e.NewEnd) && Page.User.HasEditPermission(user, eventId)) { dbUpdateEvent(eventId, e.NewStart, e.NewEnd); GetEvents(); DPCal.Update(); } } } 

下面是我的Global.asax.cs文件:

 public class Global : System.Web.HttpApplication { protected void Application_Error(object sender, EventArgs e) { Server.Transfer("~/GlobalExceptionHandler.aspx?ReturnUrl=" + Request.Path); } } 

下面是我的自定义IHttpModule处理程序:

 public class UnhandledExceptionModule : IHttpModule { private HttpApplication _context; private bool _initialized = false; public void Init(HttpApplication context) { _context = context; _initialized = true; context.Error += new EventHandler(Application_Error); } public UnhandledExceptionModule() { _initialized = false; } public void Dispose() { if (_initialized) _context.Dispose(); } public void Application_Error(object sender, EventArgs e) { if (_initialized) _context.Server.Transfer("~/GlobalExceptionHandler.aspx?ReturnUrl=" + _context.Request.Path); } } 

永远不会到达GlobalExceptionHandler.aspx上的Page_Load。

事实certificate问题是由于DPCal_EventMove方法作为页面回调执行而引起的。 幸运的是,DayPilot日历组件可以选择更改此行为。 一旦我将DayPilot:DayPilotCalendar控件的EventMoveHandling属性更改为“PostBack”而不是“CallBack”,我就能够捕获并处理安全exception。

你有没有尝试过:

 public class Global : System.Web.HttpApplication { protected void Application_Error(object sender, EventArgs e) { Server.Transfer("~/GlobalExceptionHandler.aspx?ReturnUrl=" + Request.Path); } } 

加:

 private void Page_Error(object sender, System.EventArgs e) { //errorcode } 

到你的页面代码,看看是否在错误期间调用了它?