Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CustomErrors does not work when setting redirectMode="ResponseRewrite"

In a old site, I was changing the way that CustomErrors works by adding redirectMode="ResponseRewrite" (new in 3.5 SP1):

<customErrors mode="RemoteOnly" defaultRedirect="Error.aspx" redirectMode="ResponseRewrite">     <error statusCode="404" redirect="404.aspx" /> </customErrors>  

The thing is: it shows me the generic error page (the one that you get when you don't set customErrors. If I remove theredirectMode="ResponseRewrite" part, it works fine.

I'm sure 3.5 SP1 is installed in the server, because I use the same setting on other sites hosted in the same server.

Any ideas?

like image 422
Eduardo Molteni Avatar asked Apr 23 '09 14:04

Eduardo Molteni


People also ask

Where do you put customErrors mode off?

The customErrors tag must be placed within tags. Create a <customErrors> tag within a "web. config" configuration file located in the root directory of the current web application. This <customErrors> tag should then have its "mode" attribute set to "Off".

What is customErrors mode RemoteOnly?

RemoteOnly will give end users the custom error message and local usrs the standard asp.net error page. If your developers use a local web server for development you have both in one. Another approach is to set the <customErrors> to Off on development servers and set it to On in the production environment.

How do I turn off custom error mode?

Choose the ASP.NET tab. Click on "Edit Configuration". Click the Custom Errors tab. Select Off for custom error mode.


1 Answers

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/Whatever, not find it on the file system, and return a generic 404 error page!

like image 162
Michael Hallock Avatar answered Sep 18 '22 16:09

Michael Hallock