Can't get defaultRedirect to work

The defaultRedirect won't go directly to a view. Your defaultRedirect looks like a razor view file which it can't process. For example: Where does it get the model from? It isn't, and can't, be specified in the config file so it can't process a view.

If you want more dynamic error pages in MVC you might want to read custom error pages and error handling in MVC 3


It works for me. Just make this change in web.config:

<system.web>
    <customErrors mode="On" defaultRedirect="~/Views/Shared/Error.cshtml">
    </customErrors>
</system.web>

Edit you web.config as:

<system.web>
    <customErrors mode="On" defaultRedirect="/Home/Error" />
</system.web>

If you use asp.net mvc 1.0 or 2.0, you should add HandleError attribute for each controller:

[HandleError]
public class HomeController: Controller
{
    public ActionResult Error()
    {
        return View();
    }
}

if you use asp.net mvc 3.0:

public class MvcApplication : System.Web.HttpApplication
{
        protected void Application_Start()
        {
            GlobalFilters.Filters.Add(new HandleErrorAttribute());
        }
}