Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't get defaultRedirect to work

In my web.config, I have:

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

In Views/Shared/Error.cshtml, I have:

@model System.Web.Mvc.HandleErrorInfo
@{
    ViewBag.Title = "Error";
}
<h2>
    Sorry, an error occurred while processing your request.
</h2>

If I put an invalid URL/route into my browser, I get this:

Server Error in '/' Application.

The resource cannot be found.

Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

Requested URL: /Error.cshtml

Why can't Error.cshtml be found? The file is definitely in Views/Shared.

like image 475
devuxer Avatar asked Jun 02 '11 07:06

devuxer


1 Answers

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

<system.web>
    <customErrors mode="On" defaultRedirect="~/Views/Shared/Error.cshtml">
    </customErrors>
</system.web>
like image 144
Rajesh Avatar answered Oct 10 '22 17:10

Rajesh