我有在代码中实现这样的自定义错误处理程序:为什么我的自定义错误处理工作不正常?
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
'get the exception
Dim ex = Server.GetLastError()
'log it
ex.LogToFile()
'clear the error
Server.ClearError()
'build route data to route this exception to ErrorController
Dim routeData = New RouteData()
routeData.Values.Add("controller", "Error")
routeData.Values.Add("action", "Index")
routeData.Values.Add("exception", ex)
'route to the error controller, preserving the context
Dim controller As IController = New Controllers.ErrorController()
controller.Execute(New RequestContext(New HttpContextWrapper(Context), routeData))
End Sub
然后/error/index
操作方法在一个用户友好的方式除外。在我的开发机器上,这工作正常。但是在部署的服务器上,当引发异常而不是我的错误消息时,它会尝试使用预设的错误页面,如%SystemDrive%\inetpub\custerr\<LANGUAGE-TAG>\500.htm
。
如果我指定了我自己的500页,它将使用它,但是没有我的自定义处理。
如果我删除了500页,像这样:
<httpErrors>
<remove statusCode="500" subStatusCode="-1" />
</httpErrors>
我只是得到死亡的白色屏幕此消息:
The page cannot be displayed because an internal server error has occurred.
那么,怎样才能让我的错误处理做正确的事情?