Tôi có một phương thức của một lớp (DPCal_EventMove) mà tôi muốn giới hạn quyền truy cập bằng cách sử dụng Vai trò. Tôi có cả trình xử lý lỗi Global.asax.cs và trình xử lý lỗi IHttpModule tùy chỉnh nhằm nắm bắt các ngoại lệ không được xử lý và Server.Transfer chúng thành GlobalExceptionHandler.aspx, kiểm tra xem các lỗi là SecurityExceptions có nguồn gốc từ các kiểm tra PrincipalPermission không thành công hay không. Vì một lý do nào đó, ngoại lệ không được giải quyết gây ra bởi phương thức được trang trí bằng PricipalPermission không được định tuyến thông qua một trong các trình xử lý lỗi của tôi. Câu hỏi của tôi là: Trường hợp ngoại lệ này được định tuyến đến đâu và làm thế nào để tôi nắm bắt và xử lý nó?Ngoại lệ chưa xử lý không bị xử lý lỗi Global.asax hoặc trình xử lý lỗi IHttpModule tùy chỉnh
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();
}
}
}
Dưới đây là tập tin Global.asax.cs của tôi:
public class Global : System.Web.HttpApplication
{
protected void Application_Error(object sender, EventArgs e)
{
Server.Transfer("~/GlobalExceptionHandler.aspx?ReturnUrl=" + Request.Path);
}
}
Dưới đây là tùy chỉnh IHttpModule xử lý của tôi:
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 trên GlobalExceptionHandler.aspx không bao giờ đạt được.
Tôi nghĩ rằng liên kết này có thể có một số thông tin tốt cho bạn: http://stackoverflow.com/questions/2192093/wcf-principalpermission-attribute-exception-loggin –
Nếu bạn gặp lỗi trong khi gọi lại trang qua một WebMethod , bạn sẽ phải xử lý lỗi một cách thích hợp ở phía máy khách. Có thể bạn có thể gửi một phiên bản (đơn giản) của mã của bạn khi (1) gọi 'DPCal_EventMove' và (2) định nghĩa' DPCal_EventMove'? –