I’ve been struggling with Anthem.NET for some time to work exactly how I would like (and expect) as regards to the event flow for an unhandled page exception.
In the original 1.5.1 release of Anthem, the Application_Error event was bypassed by a hook added in Manager.OnError as follows:
Which meant that any global logging (we use log4net) of an error that you do in Application_Error does not fire and so you end up with the unsatisfactory situation where errors in callbacks occur silently to your operations team whilst returning correct information back to the JS client portion of Anthem.
This can be worked around by writing a JS Anthem error handler that then calls an AJAX method which triggers a log of a message, but that is convoluted, inefficient and unrelhable and not an acceptable solution for me.
In the latest source of AnthemNxt I’ve removed the above OnError handler and let the exception proceed as a normal postback would (so my Application_Error handler DOES get hit now and I get exceptions fully logged).
However now there is a HTML error page returned to the JS client and not a valid JSON response because the OnUnload Anthem handler is never called (since the page rendering is hijacked due to the exception). Until I can write a HttpModule to overcome this and make AnthemNxt a true drop-in library, I’ve broken out the OnUnload AnthemNxt functionality so that it can be called from Application_Error:
Hopefully with a HttpModule I can make this fully automatic, but for our purposes this is better than the existing behaviour for now
Anyone interested in contributing, whether it be patches, comments or just bugs please get in touch or use the Codeplex project.