我们有一个混合的MVC和asp.net应用程序,客户错误设置为关闭。
<customErrors mode="Off" >
当抛出未处理的异常时,Global.asax会像这样处理错误。
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
这一切都适用于开发环境和当前的实时环境(带有iis 7.5的Server 2008 R2),但在部署到我们的新环境(Windows Server 2012 R2和IIS 8)时,我们得到一个500错误页面,这似乎只会发生对于500个错误,404错误似乎处理得很好。
我知道Application_Error,ExecuteErrorController和控制器被调用,因为错误是通过控制器记录的,但控制器返回的视图没有显示而是我得到了
此页面目前无法处理此请求。 HTTP 错误500
我是否遗漏了移动到iis 8的内容以使其正常工作?