in my web.config blow you can see redirectMode="ResponseRewrite". I read this is what I need to preserve the status code. Unfortunately as soon as I have it in, I get:
"An exception occurred while processing your request. Additionally, another exception occurred while executing the custom error page for the first exception. The request has been terminated."
Omitting this variable successfully redirects me to ~/Error/Index.cshtml but has a response of 200. doh. Any direction would be hugely appreciated, thanks.
<system.web>
<compilation debug="true" targetFramework="4.5" />
<customErrors mode="On" redirectMode="ResponseRewrite" defaultRedirect="~/Error/Index">
<error statusCode="404" redirect="~/Error/Index"/>
<error statusCode="500" redirect="~/Error/Index"/>
</customErrors>
<httpRuntime targetFramework="4.5" />
</system.web>
<system.webServer>
<httpErrors errorMode="Custom" existingResponse="Auto" defaultResponseMode="ExecuteURL">
<remove statusCode="403"/>
<remove statusCode="404"/>
<remove statusCode="500"/>
<error statusCode="403" path="~/Error/Index" responseMode="File"/>
<error statusCode="404" path="~/Error/Index" responseMode="File"/>
<error statusCode="500" path="~/Error/Index" responseMode="File"/>
</httpErrors>
</system.webServer>
In my filterconfig.cs:
public class FilterConfig
{
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
// does this conflict?
filters.Add(new HandleErrorAttribute());
}
}