Last post Mar 04, 2013 06:47 AM by jayesh_sorathia
Sep 06, 2011 08:44 AM|w0051977|LINK
I am using the ASP.NET GeneratedImage control (http://weblogs.asp.net/craigshoemaker/archive/2008/08/19/new-asp-net-generated-image-control.aspx)
The event handler seems to receive multiple requests at once from the same client. Is this correct? For example, if a web page contains three images, then the Image Handler is called three times almost all at once (after the page is loaded).
This is happening when I step through the code.
I would expect each image to be requested individually.
Sep 06, 2011 11:10 AM|Jmurekezi|LINK
ImageHandler is an absufucation process instead of using href, what is happening is you are telling your code to go to the webserver and fetch everything with the extension so it will loop through the location on the server x amount of time until it has
gone through all the images and returns all the images. you can limit what you display but that doesn't mean that the code won't keep looking for it. A typical example is a foreach.
The best way is to pass in a name to look for ad then it will go to the server if filename found then returns the image otherwise it will continue to look.
Sep 06, 2011 03:48 PM|w0051977|LINK
Thanks for the reply, however I am still confused about the behaviour of my application.
The ASP.NET page loads correctly, which contains three images. The image handler is then called. I have put a breakpoint in the image handler, however when I step through the code the program seems to jump back to the beginning of the image handler before
it has handled the current image e.g. it gets to line five and then goes back to line one (perhaps because the second image needs to be handled). Could you explain what is happening? Thanks.
Sep 07, 2011 04:17 AM|Jmurekezi|LINK
please read this http://forums.asp.net/t/1011421.aspx/1 and also try to read on the handler.
For me t understand where you are coming from, I may need to look at your code if you don't mind otherwise it is hard to give an explanation to something you haven't seen and also can u please state the problem you are trying to solve.
Sep 07, 2011 04:59 AM|Jmurekezi|LINK
also have a look on this and see if it can be more useful, I myself found this article much more useful.
Sep 07, 2011 06:07 AM|w0051977|LINK
Thanks for the reply.
The page, which contains the images (there are three images) finishes loading and then the images are requested. However, three errors seem to hit application_error event (in Global.asax) at the same time, which means the log file referenced in application_error
is locked. Here is what I think is happening:
1) Image Handler returns a null image for image 1 (because there is no BLOB in the database). An exception is thrown somewhere and control passed to application_error. The log file is opened and the exception written to it.
2) Before the log file is closed (see part 1) the image handler returns a null for image 2 (because there is no BLOB in the database). However, the log file is still locked from part 1 and an exception is thrown in the application_error event.
3) Image Handler returns a null image for image 3 (because there is no BLOB in the database). An exception is thrown somewhere and control passed to application_error. At this point the error log file lock is released (see 1), so the error is written to
the error log as expected.
I would expect that if an error occurs whilst the images are fetched, then processing is stopped until the error is delt with i.e. if an error occurs when image 1 is fetched, the image 2 is not fetched until the error from image 1 is delat with. However
this does not appear to be the case. If this does not make sense then I will post some code. Regards.
Sep 07, 2011 09:42 AM|Jmurekezi|LINK
From what you are teling me I would advise you to look at the example from the code project article as your issue can be resolved from there. I used it and found it helpful,
One thing though are u saving your image in DB? if so would advise you to save the image in a directory and save filename in db. what you would do is have a query that returns the list of images you are looking for and loop through the directory(using the
handler) return the image in the context and display them as and when needed. This would remove the overhead of trying to look for something which isn't there and can help you add much more functionality to the way you manipulate your images(can use JQuery
to have some fancy album etc...)
as to the error, what happens when you try and catch?
Sep 08, 2011 09:10 AM|w0051977|LINK
Thanks for the reply. The article you provided describes how the Image Handler works, but my question is specifically about errors thrown by the image handler. I have had a look at the exception object and here are the properties:
source: Microsoft.Web.GeneratedImage (this is a component that I downloaded - see the URL in the first post)
Target site: System.Reflection.RuntimeMethodInfo
Stack Trace: at Microsoft.Web.ImageHandlerInternal.HandleImageRequest(HTTPContextBase context, Func 2' ImageCallBack, String uniqueIDStringSeed)
I don't understand why multiple errors seem to hit application_error at the same time. For example, there are three images on my page and the same error hits application_error three times at once. I would expect one error to hit application_error at a
time i.e. wait until each one is handled. Does this make sense? Regards.
Sep 09, 2011 03:48 AM|Jmurekezi|LINK
You should read my first post, depending on how many images you have/ trying to display, the handler will hit the webserver x amount of time. the application error follows on your design.Can you ue fiddler or charles to see what is going on?
You shouldn't expect any kind of error from your software, if you get one then go back to design.
The control you are refering to, I have tried it and found it not useful(in my situation).
There is a niece chapter about handler on msdn, I think you should give it a try.
It is so hard for me to give you any insight as to why something is happening without anycode/ the purpose of your software, if you want me to help you more please post your code here.
Mar 04, 2013 06:47 AM|jayesh_sorathia|LINK
Here is image handler example code and also contains details how to configure image handler in web.config file with downloadable examples.