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 );}}