I'm using ASHX file to creating images in a dynamic way.
I added a line of code to throw an exception in my ashx file. if I browse to ashx file directly, my application_error in global.asax is working fine to handle the error.
my problem is application_Error is not working when I use this handler in another page. like in show.aspx if I put:
<img src="image.ashx" />
there would be no errors, just a blank image. I even tried a custom httpmodule to handle errors, but no luck. so how can I catch errors in ashx file?
Update: to make things more clear, for exception catching I have 2 options in mind.
first is to redirect user to another page if for ANY reason, image generation goes wrong.
second is to replace the image with my static png file again if ANY reason caused some errors in ashx file.
that's why I thought using httpapplication.error would help. my httpmodule is like:
Public Sub Init(ByVal context As System.Web.HttpApplication) Implements system.Web.IHttpModule.Init
AddHandler context.Error, AddressOf OnError
End Sub
Private Sub OnError(ByVal sender As Object, ByVal e As EventArgs)
Dim app As HttpApplication = CType(sender, HttpApplication)
End Sub
So how can I achieve these in OnError ?