The custom Json and aopjson are returned after AOP exception capture in. net mvc.

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.