Image Handler - Generated Imageshttp://forums.asp.net/t/1717734.aspx/1?Image+Handler+Generated+ImagesMon, 04 Mar 2013 10:47:34 -050017177344584936http://forums.asp.net/p/1717734/4584936.aspx/1?Image+Handler+Generated+ImagesImage Handler - Generated Images <p>Hi,</p> <p>I am using the ASP.NET GeneratedImage control (<a href="http://weblogs.asp.net/craigshoemaker/archive/2008/08/19/new-asp-net-generated-image-control.aspx">http://weblogs.asp.net/craigshoemaker/archive/2008/08/19/new-asp-net-generated-image-control.aspx</a>)</p> <p>The event handler seems to receive multiple requests at once from the same client.&nbsp; 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).&nbsp; <br> This is happening when I step through the code.</p> <p>I would expect each image to be requested individually.</p> 2011-09-06T12:44:45-04:004585156http://forums.asp.net/p/1717734/4585156.aspx/1?Re+Image+Handler+Generated+ImagesRe: Image Handler - Generated Images <p>Hi,</p> <p></p> <p>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.</p> <p>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.</p> <p></p> <p>Regards</p> 2011-09-06T15:10:15-04:004585512http://forums.asp.net/p/1717734/4585512.aspx/1?Re+Image+Handler+Generated+ImagesRe: Image Handler - Generated Images <p>Thanks for the reply, however I am still confused about the behaviour of my application.</p> <p></p> <p>The ASP.NET page loads correctly, which contains three images.&nbsp; The image handler is then called.&nbsp; 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).&nbsp; Could you explain what is happening? Thanks.</p> 2011-09-06T19:48:54-04:004586229http://forums.asp.net/p/1717734/4586229.aspx/1?Re+Image+Handler+Generated+ImagesRe: Image Handler - Generated Images <p>please read this&nbsp;<a href="../../../../t/1011421.aspx/1">http://forums.asp.net/t/1011421.aspx/1</a>&nbsp;and also try to read on the handler.&nbsp;</p> <p></p> <p>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.</p> <p></p> <p>Regards</p> 2011-09-07T08:17:15-04:004586331http://forums.asp.net/p/1717734/4586331.aspx/1?Re+Image+Handler+Generated+ImagesRe: Image Handler - Generated Images <p>also have a look on this and see if it can be more useful, I myself found this article much more useful.</p> <p><a href="http://www.codeproject.com/KB/aspnet/CustomImageHandler.aspx">http://www.codeproject.com/KB/aspnet/CustomImageHandler.aspx</a></p> <p>Regards</p> 2011-09-07T08:59:41-04:004586490http://forums.asp.net/p/1717734/4586490.aspx/1?Re+Image+Handler+Generated+ImagesRe: Image Handler - Generated Images <p>Thanks for the reply.</p> <p></p> <p>The page, which contains the images (there are three images) finishes loading and then the images are requested.&nbsp; 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.&nbsp; Here is what I think is happening:</p> <p></p> <p>1)&nbsp; Image Handler returns a null image for image 1 (because there is no BLOB in the database).&nbsp; An exception is thrown somewhere and control passed to application_error.&nbsp; The log file is opened and the exception written to it.</p> <p>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).&nbsp; However, the log file is still locked from part 1 and an exception is thrown in the application_error event.</p> <p>3) Image Handler returns a null image for image 3 (because there is no BLOB in the database).&nbsp; An exception is thrown somewhere and control passed to application_error.&nbsp; At this point the error log file lock is released (see 1), so the error is written to the error log as expected.</p> <p>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.&nbsp; However this does not appear to be the case.&nbsp; If this does not make sense then I will post some code.&nbsp; Regards.</p> 2011-09-07T10:07:59-04:004586929http://forums.asp.net/p/1717734/4586929.aspx/1?Re+Image+Handler+Generated+ImagesRe: Image Handler - Generated Images <p>Hi,</p> <p></p> <p>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,</p> <p>One thing though are u saving your image in DB? if so &nbsp;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...)</p> <p></p> <p>as to the error, what happens when you try and catch?</p> <p></p> <p>Regards</p> 2011-09-07T13:42:43-04:004588573http://forums.asp.net/p/1717734/4588573.aspx/1?Re+Image+Handler+Generated+ImagesRe: Image Handler - Generated Images <p>Thanks for the reply.&nbsp; The article you provided describes how the Image Handler works, but my question is specifically about errors thrown by the image handler.&nbsp; I have had a look at the exception object and here are the properties:</p> <p>source: Microsoft.Web.GeneratedImage (this is a component that I downloaded - see the URL in the first post)</p> <p>Target site: System.Reflection.RuntimeMethodInfo</p> <p>Stack Trace: at Microsoft.Web.ImageHandlerInternal.HandleImageRequest(HTTPContextBase context, Func 2' ImageCallBack, String uniqueIDStringSeed)</p> <p>I don't understand why multiple errors seem to hit application_error at the same time.&nbsp; For example, there are three images on my page and the same error hits application_error three times at once.&nbsp; I would expect one error to hit application_error at a time i.e. wait until each one is handled.&nbsp; Does this make sense? Regards.</p> 2011-09-08T13:10:09-04:004589702http://forums.asp.net/p/1717734/4589702.aspx/1?Re+Image+Handler+Generated+ImagesRe: Image Handler - Generated Images <p>Hi Mate,</p> <p></p> <p>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?</p> <p>You shouldn't expect any kind of error from your software, if you get one then go back to design.</p> <p>The control you are refering to, I have tried it and found it not useful(in my situation).</p> <p>There is a niece chapter about handler on msdn, I think you should give it a try.</p> <p>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.</p> <p></p> <p>Regards</p> 2011-09-09T07:48:33-04:005320906http://forums.asp.net/p/1717734/5320906.aspx/1?Re+Image+Handler+Generated+ImagesRe: Image Handler - Generated Images <p>Here is image handler example code and also contains details how to configure image handler in web.config file with downloadable examples. <a target="_self" href="http://jayeshsorathia.blogspot.com/2013/02/mapping-file-extension-in-iis-for-http-handler.html"> <strong>Click here...</strong></a><br> <br> </p> 2013-03-04T10:47:34-05:00