Custom Errors on ASP.Net MVC - redirectMode="ResponseRewrite" Issue
Today, I was wraping up an asp.net mvc project. Make it prettier and safer. I realised that there is a thing which doesn't quite work with asp.net mvc. CustomErrors !
I wanted to refill the page, which has one or multiple errors, with a custom error page so I implemented the following code on web.config file;
Then, I hit an error on pupose just in case to see if it works or not and Boom... !! It failed ! It gave me the famous ASP.Net yellow screen of death;
I was a little surprised about that and I wonder why that thing happened. So I made a little research and I opened a thread on ASP.Net MVC Forums
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!
The answer is pretty reasonable for me and I changed the RedirectMode to ResponseRedirect which is the default one.
But I still wonder that ASP.Net Mvc team will fix it in next versions or not....