In ASP. net mvc, when redirectmode = "responserewrite", the controller cannot be used to set specific error pages.
I made the following settings:
(1) web. config:
<Customerrors mode = "on" redirectmode = "responserewrite" defaultredirect = "error/defaulterror">
<Error statuscode = "404" Redirect = "error/404"/>
</Customerrors>
(2) errorcontroller. CS:
Public actionresult error (string errorcode)
{
Viewdata ["errorcode"] = errorcode;
Return view ();
}
The following error occurs:
Server Error in '/'application.
--------------------------------------------------------------------------------
The resource cannot be found.
Description: HTTP 404. the resource you are looking for (or one of its Dependencies) cocould have been removed, had its name changed, or is temporarily unavailable. please review the following URL and make sure that it is spelled correctly.
Requested URL :/
The system used server. Transfer to Display Error information when responserewrite was found. The server. Transfer and Asp.net MV routes are incompatible. Therefore, if "responserewrite" is used, the Redirect in defaultredirect or error tag must be an existing page. The configuration is as follows:
<Customerrors mode = "on" redirectmode = "responserewrite" defaultredirect = "~ /Common/error/defaulterror. aspx ">
<Error statuscode = "404" Redirect = "~ /Common/error/404. aspx "/>
</Customerrors>
It is important to note for anyone trying to do this in an MVC application that responserewrite uses server. transfer behind the scenes. therefore, the defaultredirect must correspond to a legitimate file on the file system. apparently, server. transfer is not compatible with MVC routes, therefore, if your error page is served by a controller action, server. transfer is going to look for/error/whatev Er, not find it on the file system, and return a generic 404 error page!