我正在研究我们在集成模式下运行IIS 7时遇到的问题。我们有几个应用程序在.net 3.5中运行。我们总是捕获并处理未处理的异常的标准方法是利用Global.asax中的Application_Error方法(在这种情况下,未处理的异常是在对不具有'的aspx页面发出请求时创建的HttpException。存在)。
在Application_Error内部,我们使用自定义错误处理将错误记录到数据库,发送警报电子邮件,然后重定向到指定的错误页面。错误日志记录和警报电子邮件按预期工作。重定向没有。
我已经使用Fiddler来查看请求/响应,并且我将HTTP 302添加到与我的customErrors部分完全不同的页面。
为什么没有Response.Redirect在Application_Error中工作?
到目前为止,这是我的代码:
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
Dim ex As System.Exception = Server.GetLastError
Server.ClearError()
If Not (TypeOf (ex) Is HttpException) Then
//Run our internal error handling here
Else
Dim httpEx As HttpException = CType(ex, HttpException)
Response.Clear()
Response.StatusCode = httpEx.GetHttpCode()
Response.TrySkipIisCustomErrors = True
Server.Transfer("../Error.htm")
End If
End Sub
当我尝试访问不存在的aspx页面时运行正常。但是,它不适用于静态页面。
我已经尝试了很多变体,这些代码当前正在运行,没有customErrors或httpErrors部分。