我有一个类 (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。