Handling Errors (i.e. Content Length) Within an HttpHandler
I'm working on an uploader built with an HttpHandler. I would like to create a routine to handle all uncaught errors including content length error.
<%@ webhandler class="MyNamespace.UploadHandler" %>
Namespace MyNamespace
Class UploadHandler
Implements IHttpHandler
ReadOnly Property IsReusable As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property
Sub Page_Error(sende开发者_StackOverflowr As Object,e As EventArgs)
' Never fires
End Sub
Sub ProcessRequest(context As HttpContext) Implements IHttpHandler.ProcessRequest
...
End Sub
End Class
End Namespace
It's critical that I handle any 404.13 (request exceeds request content length) error in the httphandler itself.
I would also like Page_Error to handle any uncaught exceptions but it never fires.
Apparently this just cannot be done. From scouring the net, it seems that the only possible place to catch the 404.13 error is in Application_BeginRequest. I don't think that's going to work for my purposes but maybe it will help someone else. I'll be handling the error from the JavaScript side.
As to Page_Error - that's not part of HttpHandler so the only solution is a try/catch block around the work done in ProcessRequest.
精彩评论