locked
Httphandler works intermittently RRS feed

  • Question

  • User1464092154 posted
    Hi Guys,

    I wrote an image httphandler that works 60% of the time.

    I'm trying to render 10 images on 1 page... ex. MyImage.aspx?id=1 , MyImage.aspx?id=2 etc. Every now and again (when I'm lucky) all 10 images load, other times only 6 or 5 or some random number of images load. The ProcessRequest method executes the same amount of random times.

    Is there some setting which I should change in the web.config to handle a few simultaneous requests?? Or whats going on??
    Friday, November 17, 2006 5:25 AM

All replies

  • User2032526919 posted
    Can you share any details about the implementation? Is there something that would prevent them being "loaded"? Is it serving them from file system, database or generating on-fly?
    Sunday, November 19, 2006 3:02 PM
  • User1464092154 posted

    The images are retrieved from the database... My httphandler code is as follows:


    1    	public class DSProductImageHandler : IHttpHandler 
    2    	{ 
    3    		public bool IsReusable { get { return false; } } 
    4        
    5    		public void ProcessRequest(HttpContext ctx) 
    6    		{ 
    7    			int id = Int32.Parse(ctx.Request["id"].ToString());
    8    
    9    			DSProductImageController imageCtrl = new DSProductImageController();
    10   			DSProductImageInfo inf = imageCtrl.GetByDSProduct(id);
    11   
    12   			if (inf == null) 
    13   			{
    14   				inf = new DSProductImageInfo();
    15   				StreamReader str = new StreamReader(ctx.Server.MapPath("/images/noImage.jpg"));
    16   				inf.Image = DotSlash.DNN.Modules.Components.Utilities.StreamToBytes(str.BaseStream, 32768);
    17   			}
    18   			
    19   			ctx.Response.ContentType = "image/jpeg";
    20   			ctx.Response.AddHeader("Content-Disposition", "attachment; filename=product.jpg");
    21   			ctx.Response.BinaryWrite(inf.Image);
    22   		} 
    23   	} 
    
     
     
    Monday, November 20, 2006 6:15 AM
  • User-1417632248 posted

    One query on your code snippet , I think DSProductImageInfo  Class may not thread safe in your case, then wrap it with a lock on that object and also add  "id" to file name to give a unique file name to the stream as follows

    1      	    lock (inf)
    2                  {	
    3    	     if (inf == null) 
    4       			{
    5       				inf = new DSProductImageInfo();
    6      				StreamReader str = new StreamReader(ctx.Server.MapPath("/images/noImage.jpg"));
    7       				inf.Image = DotSlash.DNN.Modules.Components.Utilities.StreamToBytes(str.BaseStream, 32768);
    8       			}
    9       			
    10      			ctx.Response.ContentType = "image/jpeg";
    11      			ctx.Response.AddHeader("Content-Disposition", "attachment; filename=product" + id.ToString() + ".jpg");
    12      			ctx.Response.BinaryWrite(inf.Image);
    13                     }
    14      	} 
    15   
    
    Hope this will be helpful..
    -thank you,
    Techieguys

     

     

    Monday, November 27, 2006 6:06 PM