0

我使用標準單軌/ Windsor/ActiveRecord堆棧來構建Web應用程序。在Web應用程序中,控制器使用xml配置文件註冊(對於Windsor)。在CastleProject單軌中捕獲ControllerNotFoundException

當配置文件中沒有定義控制器時,MonoRailHttpHandlerFactory將會(顯然)拋出ControllerNotFoundException異常。

有沒有辦法捕捉這個異常並向用戶顯示自定義消息?

回答

1

您可以隨時在GLobalApplication中的Application_OnError()事件處理程序中找到錯誤。我們這樣做:

public virtual void Application_OnError() 
    { 
     var error = Server.GetLastError(); 

     if (error.GetType() != typeof(ControllerNotFoundException)) 
      return; 

     // We don't want these errors in the event log 
     Server.ClearError(); 

     //Handle page not found 

     Server.TransferRequest("/rescue/pagenotfound"); 
    }