Add customerrors for httpstatuscoderesult

Source: Internet
Author: User

When the return value of Asp.net MVC action is httpstatuscoderesult, customerrors always does not work.

(404 in case of 500 and exception, because they are not returned values of the httpstatuscoderesult type, they can also be used)

The solution is as follows:

1. Enable customerrors (to keep the original errors such as 404 and 500)

2. Enable httperrors (dedicated statuscode)

3. Set Global: Response. tryskipiiscustomerrors = true;

<System. Web> <customerrors mode = "on" defaultredirect = "~ /Home/error "> <error statuscode =" 404 "Redirect = "~ /Home/error/404 "/> <error statuscode =" 500 "Redirect = "~ /Home/error/500 "/> </customerrors> </system. web> <system. webserver>  


 

Protected void application_error (Object sender, eventargs e) {response. tryskipiiscustomerrors = true; Exception exc = server. getlasterror (); If (EXC is httpunhandledexception) {server. transfer ("home/error/500", true );}}


 

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.