In ASP. net mvc, when redirectmode = "responserewrite", the controller cannot be used to set specific error pages.

Source: Internet
Author: User

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!

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.