未处理的异常没有任何的Global.asax错误处理或自定义的IHttpModule错误处理程序捕获 [英] Unhandled exception not caught by either Global.asax error handler or custom IHttpModule error handler

查看:537
本文介绍了未处理的异常没有任何的Global.asax错误处理或自定义的IHttpModule错误处理程序捕获的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类(DPCal_EventMove),我要访问限制使用角色的一种方法。我同时拥有的Global.asax.cs错误处理程序,并打算异常和Server.Transfer的他们抓住未处理到GlobalExceptionHandler.aspx,检查,看看是否错误是源于失败检查的PrincipalPermission一个SecurityExceptions IHttpModule的自定义错误处理程序。出于某种原因,造成PricipalPermission装饰方法未处理的异常没有或者通过我的错误处理程序的路由。我的问题是:哪里是这个异常被路由到,如何捕获并处理它

I have one method of a class (DPCal_EventMove) that I want to limit access to using Roles. I have both a Global.asax.cs error handler and a custom IHttpModule error handler intended to catch unhandled exceptions and Server.Transfer them to GlobalExceptionHandler.aspx, which checks to see if the errors are SecurityExceptions that originated from failed PrincipalPermission checks. For some reason, the unhandled exception caused by the PricipalPermission-decorated method is not routed through either of my error handlers. My question is: Where is this exception being routed to and how do I catch and handle it?

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文件:

Below is my Global.asax.cs file:

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



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

Below is my custom IHttpModule handler:

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);
    }
}



上的Page_Load是GlobalExceptionHandler.aspx从未达到。

Page_Load on GlobalExceptionHandler.aspx is never reached.

推荐答案

原来,这个问题是因为DPCal_EventMove方法作为页面回调执行造成的。幸运的是,DayPilot日历组件有一个选项可以更改此行为。有一次,我改变了DayPilot的EventMoveHandling属性:DayPilotCalendar控制回传,而不是回调,我是能够捕获和处理安全例外

It turned out that the problem was caused because the DPCal_EventMove method was executing as a page callback. Fortunately, the DayPilot calendar component has an option to change this behavior. Once I changed the EventMoveHandling property of the DayPilot:DayPilotCalendar control to "PostBack" instead of "CallBack", I was able to catch and handle the security exception.

这篇关于未处理的异常没有任何的Global.asax错误处理或自定义的IHttpModule错误处理程序捕获的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆