Mat*_*att 7 c# asp.net error-handling principalpermission
我有一个类(DPCal_EventMove)的方法,我想限制使用角色的访问.我有一个Global.asax.cs错误处理程序和一个自定义IHttpModule错误处理程序,用于捕获未处理的异常和Server.Transfer他们GlobalExceptionHandler.aspx,它检查错误是否是源自失败的PrincipalPermission检查的SecurityExceptions.由于某种原因,由PricipalPermission修饰的方法引起的未处理异常不会通过我的任何一个错误处理程序进行路由.我的问题是:这个异常被路由到哪里以及如何捕获和处理它?
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.
事实证明,该问题是由于 DPCal_EventMove 方法作为页面回调执行而引起的。幸运的是,DayPilot 日历组件可以选择更改此行为。一旦我将 DayPilot:DayPilotCalendar 控件的 EventMoveHandling 属性更改为“PostBack”而不是“CallBack”,我就能够捕获并处理安全异常。
| 归档时间: | 
 | 
| 查看次数: | 1518 次 | 
| 最近记录: |