rss
[ Log On ]

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...
12/8/2010 11:17:17 PM 3 comments 6032 times

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;

UploadedByAuthors/customErrors-redirectMode-ResponseRewrite-web-config.PNG

 

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;

yellow-screen-of-death-asp.net.PNG

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

Permalink Add to del.icio.usDigg!Share on FacebookShare on Google BuzzReddit!Stumble it!

Comments

gravatar
#122
re: Custom Errors on ASP.Net MVC - redirectMode="ResponseRewrite" Issue
by nihan on 12/10/10 18:49:56 Friday (UTC +00:00)
very good job :))
gravatar
#2069
re: Custom Errors on ASP.Net MVC - redirectMode="ResponseRewrite" Issue
by Ardin on 02/16/11 18:34:43 Wednesday (UTC +00:00)

apperently, the best way of retuning 404 error is to handle them on your controller. I mean, you cannot handle all of them but you can predict that on one conditions this will going to retun a null page so lets throw 404 httpexception.

But insted, create a 404 view and redrecttoview or directly retun the view as partial


gravatar
#2070
re: Custom Errors on ASP.Net MVC - redirectMode="ResponseRewrite" Issue
by Tugberk on 02/17/11 13:56:12 Thursday (UTC +00:00)

thanks for the input.



Additional allowed tags : [quote]...[/quote], [user]...[/user]
:
:
: will not be displayed ! (but will show your Gravatar)
:
: