开发者

Catching 500 Errors after Response.Flush()

Once the data has been flushed to the page, and an error is generated in future processes, the error message is written inside the browser, instead of generating an entire 500 error on the page. How do I trap those e开发者_Python百科rrors that are written to the page after Response.Flush() is called? Send Errors to Browser is set = True, but the error isn't triggering the 500 Error page, instead it's only triggering an error message on the screen. How do I capture the error when this happens?


Once you've called Response.Flush() the response headers and all content that is in the response buffer at that time are send to the browser. The HTTP status code is on the first line of the response and thus can not be changed anymore after the headers have been sent.


The best I have found for handling this case it to put all the rendering in a Render sub (which can include %> with html), and use

On Error Resume Next

Render

If Err.number <> 0 Then
    ' Handle the error
    Response.Write "Error"
End If

When an error occur in the render, the Render sub is immediately interrupted and you can handle the error with whatever custom code you wish, including coming from an include. So that is no more a catch all solution put only in one place, but for pages requiring that flush trick, well, just use one more trick for handling their errors.

Overall page code looks like

<%@  language="VBSCRIPT" codepage="65001" %>

' Do everything that does not need any Flush
...

' Now handle the hacky part

On Error Resume Next

Render

If Err.number <> 0 Then
    ' Handle the error
    Response.Write "Error"
End If

Sub Render

<%
<!-- your part of rendering which has to do flushes -->
...
%>

End Sub


in IIS select your Virtual directory or Website then on right section under IIS section you can see ASP option select this ASP section and click on Open feature on top right part of page. Then Under Debugging Properties set true >> Send Error to the Browser

Thanks JJ

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜