سؤال

I am handing exception in Controller, and other layers that I have manually added like DataAccess.

I have also placed exception handling in Views.

Is it necessary to do so, or can I remove the exception handling code from view?

هل كانت مفيدة؟

المحلول

This is not necessary, ASP.NET haves exception handling by itself. You only have to throw a exception. The view will catch it automatically when running on 'release' mode

Just add the 'FilterConfig' in your App_start

public class FilterConfig
{
    /// <summary>
    /// The register global filters.
    /// </summary>
    /// <param name="filters">
    /// The filters.
    /// </param>
    public static void RegisterGlobalFilters(GlobalFilterCollection filters)
    {
        filters.Add(new HandleErrorAttribute());
    }
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top