7

我有一个类 (DPCal_EventMove) 的方法,我想限制对使用角色的访问。我有一个 Global.asax.cs 错误处理程序和一个自定义 IHttpModule 错误处理程序,旨在捕获未处理的异常并将它们传送到 GlobalExceptionHandler.aspx,它检查错误是否是源自失败的 PrincipalPermission 检查的 SecurityExceptions。由于某种原因,由 PricipalPermission-decorated 方法引起的未处理异常未通过我的任何一个错误处理程序进行路由。我的问题是:这个异常被路由到哪里以及如何捕获和处理它?

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。

4

3 回答 3

1

原来问题是因为 DPCal_EventMove 方法作为页面回调执行的。幸运的是,DayPilot 日历组件具有更改此行为的选项。一旦我将 DayPilot:DayPilotCalendar 控件的 EventMoveHandling 属性更改为“PostBack”而不是“CallBack”,我就能够捕获并处理安全异常。

于 2012-08-27T21:14:16.010 回答
0

你有没有尝试过:

public class Global : System.Web.HttpApplication
{
    protected void Application_Error(object sender, EventArgs e)
    {
        Server.Transfer("~/GlobalExceptionHandler.aspx?ReturnUrl=" + Request.Path);
    }
}
于 2012-08-27T14:48:30.563 回答
0

添加:

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

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

于 2012-08-29T15:59:15.793 回答