I’ve noticed if there is a compilation error in a view and custom errors is on, the framework doesn’t fire Application_Error(object sender, EventArgs e) in the ‘global.cs’, or redirect to the defaultRedirect url in the config settings.
Instead it loads the master page, changing the title to Error and putting the following
<h2> Sorry, an error occurred while processing your request. </h2>
where the view content should be.
Does anyone know a way to force it to handle these errors like any other?
PS I know there shouldn’t be any compiler errors in the view but we had a case where a view file got corrupted and was not spotted strait away as the logging code is in the Application_Error(object sender, EventArgs e).
Found it. I use an Error controller with it’s own views to handle the errors.
After some head scratching I found we still had the default Error page in the Views\Shared directory. This is what was being rendered. Why it was using this and not going the the url in the defaultRedirect part of the web.config or calling the Application_Error(object sender, EventArgs e) I don’t know.
When I deleted it, it started treating compiler exceptions the same way as all the other exceptions.