我有一个类(DPCal_EventMove)的方法,我想限制使用角色的访问权限。我有一个Global.asax.cs错误处理程序和一个自定义IHttpModule错误处理程序,用于捕获未处理的异常和Server。将它们转换为GlobalExceptionHandler.aspx,该错误处理程序检查错误是否源自失败的PrincipalPermission检查的SecurityException。出于某种原因,由PricipalPermission-decorated方法引起的未处理的异常不会通过任何一个错误处理程序进行路由。我的问题是:这个异常被传送到哪里以及如何捕获和处理它?未处理的异常未被Global.asax错误处理程序或自定义IHttpModule错误处理程序捕获
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的处理程序:永远不会达成GlobalExceptionHandler.aspx
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。
我认为这个链接可能有一些很好的信息给你:http://stackoverflow.com/questions/2192093/wcf-principalpermission-attribute-exception-loggin –
如果你在通过WebMethod进行页面回调时出错,你将不得不在客户端处理错误。 (1)调用'DPCal_EventMove'和(2)'DPCal_EventMove'的定义时,您可能会发布一个(简化版)代码吗? –