We have a mixed MVC and asp.net application with customer errors set to off.
<customErrors mode="Off" >
When an unhandled exception is thrown the Global.asax handles the error like so.
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
Dim exception = Server.GetLastError()
Dim httpContext = CType(sender, HttpApplication).Context
ExecuteErrorController(httpContext, exception)
End Sub
Sub ExecuteErrorController(httpContext As HttpContext, exception As Exception)
Dim routeData = New RouteData
routeData.Values("controller") = "Error"
routeData.Values("errorType") = 10 '
Response.Clear()
Dim httpException As HttpException = TryCast(exception, HttpException)
If httpException Is Nothing Then
routeData.Values.Add("action", "Index")
Else
'It's an Http Exception, Let's handle it.
Select Case httpException.GetHttpCode()
Case HttpStatusCode.Forbidden
' forbidden - i.e. failed Data.HasAccess checks
routeData.Values.Add("action", "HttpError403")
Exit Select
Case 404
' Page not found.
routeData.Values.Add("action", "HttpError404")
Exit Select
Case 500
' Server error.
routeData.Values.Add("action", "Index")
Exit Select
Case Else
' Here you can handle Views to other error codes.
' I choose a General error template
routeData.Values.Add("action", "Index")
Exit Select
End Select
End If
' Pass exception details to the target error View.
routeData.Values.Add("exception", exception)
Dim controller As IController = New ErrorController()
httpContext.ClearError()
Dim requestContext As RequestContext = New RequestContext(New HttpContextWrapper(httpContext), routeData)
Response.TrySkipIisCustomErrors = True
Server.ClearError()
controller.Execute(requestContext)
End Sub
This all works in the development environment and the current live environment( Server 2008 R2 with iis 7.5) but when deploying to our new environment (windows server 2012 R2 and IIS 8) we get a 500 error page this only seems to happen for 500 errors, 404 errors seem to be handled just fine.
I know Application_Error, ExecuteErrorController and the controller are been called as the error is been logged via the controller but the view which the controller returns is not been shown instead I get
This page isn’t working currently unable to handle this request. HTTP ERROR 500
Am I missing something moving to iis 8 to get this to work?