views:

191

answers:

2

In my Application_Error event handler i want to render an MVC-View for 404. I do not want to redirect because of SEO.

void Application_Error(...)
{
 if (serverException is HttpException && ((HttpException)serverException).GetHttpCode() == 404)
 {
  Server.Transfer("/error/404"); //*
 }
}

//* Fails, because it cannot find the path on disk. Of course not because it should be handled by MVC.

How to render an MVC-View from Application_Error?

I do not want to redirect.

+1  A: 

Just don't use Application_Error to handle 404 errors. Define a catch all route:

routes.MapRoute(
    "Error", 
    "{*url}", 
    new { controller = "Error", action = "Http404" });

A request that doesn't match another route will be handled by the Http404 action of the Error controller.

Darin Dimitrov
I am still using Webforms. I want a catch all solution that works for _any_ 404 sent to the client.
usr
A: 

look at the response in this question Link

Yassir
I am still using Webforms. I want a catch all solution that works for any 404 sent to the client.
usr