locked
Handle Exception in View RRS feed

  • Question

  • User-2082723756 posted

    I've written a custom FilterAttribute that implements IExceptionFilter. But this only catches exceptions in the controller actions. What is the best way to handle exceptions in views and html helper methods on a Windows 2008 64-bit Server running IIS 7?

    Rob

     

    Friday, February 5, 2010 12:37 PM

Answers

All replies

  • User1911587250 posted

    You can use elmah.

    Check out this article :

    http://volaresystems.com/Blog/post/Handling-Exceptions-in-ASPNET-MVC.aspx

    and go to How to wire this up in ASP.NET MVC section for more info.

    Hope this helps.


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, February 5, 2010 1:08 PM
  • User197322208 posted

    What is the best way to handle exceptions in views and html helper methods

    1. Catch them at compile time (ok, must not use ViewData  - but strongly typed views)

    See in MVC2 project the setting

    <MvcBuildViews>true</MvcBuildViews>

    http://devermind.com/linq/aspnet-mvc-tip-turn-on-compile-time-view-checking/

    2. For runtime ,use selenium to test the site


    Friday, February 5, 2010 4:18 PM
  • User-2082723756 posted

    Thanks for your responses. I've evaluated them but I believe I'm going to use the standard health monitoring providers that come with Asp.Net. I've used them before and they provided me with great information. It's easy to configure the application via web.config and change or add providers.

    And I'll modify my custom filter attribute so that it raises web error events, so they will be stored in the database (or whereever I configure them to go) as well.

    Rob

    Friday, February 5, 2010 4:39 PM
  • User-1005219520 posted

    [HandleError] will catch exceptions from views and HTML helper methods.  But since you can only put it on a controller or an action, it’s not global. 

    You can use ELMAH to do exception logging application-wide (not just within MVC) and across multiple controllers.  Hanselman also wrote about this - http://www.hanselman.com/blog/ELMAHErrorLoggingModulesAndHandlersForASPNETAndMVCToo.aspx.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, February 5, 2010 5:26 PM