I have custom/http errors set up in an ASP.NET MVC 3 application that will be shown on errors. My Web.Config
's httpErrors
section looks like this:
<httpErrors errorMode="Custom" existingResponse="Replace">
<remove statusCode="400" />
<remove statusCode="403" />
<remove statusCode="404" />
<remove statusCode="408" />
<remove statusCode="500" />
<remove statusCode="503" />
<error statusCode="400" responseMode="ExecuteURL" path="/Error/BadRequest" />
<error statusCode="403" responseMode="ExecuteURL" path="/Error/Forbidden" />
<error statusCode="404" responseMode="ExecuteURL" path="/Error/NotFound" />
<error statusCode="408" responseMode="ExecuteURL" path="/Error/Timeout" />
<error statusCode="500" responseMode="ExecuteURL" path="/Error/InternalServerError" />
<error statusCode="503" responseMode="ExecuteURL" path="/Error/ServiceUnavailable" />
</httpErrors>
I haven't set the customerErrors
setting as this doesn't work well with MVC & IIS 7.5.
All works fine, when an exception occurs in code.
However, when an exception is thrown in a view - it tries to show the default ~/Views/Shared/Error.cshtml
which I don't have.
The view that might throw an error could be this:
@Html.Partial("TemplateSection", Model.PreContent)
And imagine PreContent
is null, and the TemplateSection
view will fail when displaying values by doing this: @Model.Name
I read this article and have had no problems since dropping my resulting code into production 48 hours ago. Give it a whirl.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With