The custom Json and aopjson are returned after AOP exception capture in. net mvc.
Reference page:
Http://www.yuanjiaocheng.net/CSharp/Csharp-collection.html
Http://www.yuanjiaocheng.net/CSharp/Csharp-arraylist.html
Http://www.yuanjiaocheng.net/CSharp/Csharp-sortedlist.html
Http://www.yuanjiaocheng.net/CSharp/Csharp-stack.html
Http://www.yuanjiaocheng.net/CSharp/Csharp-queue.html
. Net mvc encapsulates some features to implement AOP, such as HandleErrorAttribute, ActionFilterAttribute, and AuthorizeAttribute. You can customize a feature, inherit these features, and override the methods in it to get the focus of AOP into Action. This article mainly shares a problem I encountered when using HandleErrorAttribute.
In the action, try... catch... is used for exception handling. In the catch, the author returns a json (indicating failure ). I found that all actions return the same values in catch, so I want to use HandleErrorAttribute for exception capture and then return the custom json. However, I found that filterContext. Result has been set in the OnException Method to the value I want to return, but an error is still reported during the runtime, and no json is returned after my processing. If you encounter such a problem, you can simply add a sentence, that is: filterContext. ExceptionHandled = true;
Why? You may have suddenly realized that you want to set the predictionhandled expression to true, which means that I have handled this exception. At this time, the browser looks at it, oh ~ If the exception has been handled, the json you want will be output. If you do not set it to true, the browser will report it to you as soon as it sees that there is still no Handed exception.