First explain why you are getting a few errors. The first mistake will be to try to work with the null object most likely in your model or controller. Then you will probably get the second exception when the view tries to bind to the null object, when it expects the object to exist. It's not entirely clear why you get 4 errors, but maybe because the code is trying to work with an object that is currently null.
My first suggestion would be for your OnException code to redirect the application to a friendly error page. You probably just eat every new exception and prevent web.config from handling error pages correctly if you have this setting to display the error page.
My second suggestion would be to add code to check for null objects before you start using them. These are commonly called โProtection Clausesโ and are very useful and useful for implementation. Then you can determine a convenient way to handle errors without registering an exception if you do not need to also display a friendly message to the user, except for the general "An error has occurred." message.
For example, in your controller, you can check for a null object and pass an alternate view to the user if that object is null
Function Example As ActionResult dim obj as Object = GetObject If obj is Nothing Then Return View("FriendlyNoObjectView") Else Return View(obj) End If End Function
I know this is vb (Sorry, I know it is better than C #), but the idea is the same. If you want, you can still register this as an error, but then you would not allow the error to be repeated many times. It is always good to cope with an error when it occurs and try to prevent it from popping up to the stack and cause several other errors.
Hope this helps me just understand my thoughts on reading your question.
ajrawson
source share