I have a special FilterAttribute filter, such as:
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method, AllowMultiple = true)] public sealed class ExceptionLoggingFilterAttribute : FilterAttribute, IExceptionFilter { public void OnException(ExceptionContext filterContext) { if (filterContext == null) { throw new ArgumentNullException(nameof(filterContext)); } if (filterContext.ExceptionHandled) { return; }
I registered it globally in the FilterConfig.cs file
public static class FilterConfig { public static void RegisterGlobalFilters(GlobalFilterCollection filters) { filters?.Add(new ExceptionLoggingFilterAttribute()); } }
I also have a Application_Error method declared in my global.asax.cs
protected void Application_Error(object sender, EventArgs e) { var exception = Server.GetLastError();
- When will the exception filter code be deleted, and when will it go directly to the global error handler in the Application_Error method? (I understand the concept of ExceptionHandled and understand that by marking this as processed in my filter, it will not then be cascaded to a global error handler).
An exception, which, as I thought, would fall into the filter - HttpException for 404, does not fall into the filter, but falls into the application error handler.
- I saw code examples in which people use HttpContext.Current in the global.asax.cs file to make Server.TransferRequest a concrete representation of errors. Is this the best practice? Would it be better to use the CustomErrors section in the system.web section of the web.config file?
c # model-view-controller asp.net-mvc-5
obaylis
source share