gpt4 book ai didi

c# - 未被 Global.asax 错误处理程序或自定义 IHttpModule 错误处理程序捕获的未处理异常

转载 作者:太空狗 更新时间:2023-10-29 20:40:08 28 4
gpt4 key购买 nike

我有一个类 (DPCal_EventMove) 的方法,我想限制对使用角色的访问。我有一个 Global.asax.cs 错误处理程序和一个自定义 IHttpModule 错误处理程序,用于捕获未处理的异常和 Server.Transfer 到 GlobalExceptionHandler.aspx,它会检查错误是否是源自失败的 PrincipalPermission 检查的 SecurityExceptions。出于某种原因,由 PricipalPermission 修饰的方法引起的未处理异常未通过我的任何一个错误处理程序进行路由。我的问题是:这个异常被路由到哪里,我该如何捕获和处理它?<​​/p>

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”,我就能够捕获并处理安全异常。

关于c# - 未被 Global.asax 错误处理程序或自定义 IHttpModule 错误处理程序捕获的未处理异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12101097/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com