我有一個類(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'的定義時,您可能會發佈一個(簡化版)代碼嗎? –