Custom Errors on ASP.Net MVC - redirectMode="ResponseRewrite" Issue

I assume that some of you folks have tried that in your ASP.Net MVC applications and try to figure out why it doesn't work. Well, I have figured it out...
8 December 2010
2 minutes read

Related Posts

Today, I was wraping up an mvc project. Make it prettier and safer. I realised that there is a thing which doesn't quite work with 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 

I found out that MVC Routes are not compatible with ResponseRewrite. A smilar thread was opened on and the answer is there as appears below;

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....