6

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

MartinHN
  • 19,542
  • 19
  • 89
  • 131

0 Answers0