Solved

Broken links from .axd file

Posted on 2008-06-23
5
348 Views
Last Modified: 2008-06-23
Hi,
I'm trying to troubleshoot a website whose images are broken. They're being served by an .axd file and the error message I get when I paste in the image is this:

"Could not find a part of the path" error

WHen I paste in the file info for one of the images I get this error:

 Could not find a part of the path 'd:\temp\storefront\cache\cd8435ce0d354c7fa8da7a50fe952ec7.jpg'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Any tips on troubleshooting this quickly?  I need to get this fixed yesterday.

Thanks.
0
Comment
Question by:Leprechaun
  • 3
  • 2
5 Comments
 
LVL 33

Expert Comment

by:raterus
ID: 21849263
Apparently your program thinks there should be an image at "d:\temp\..." and there isn't.  Since it's under a cache directory and has a funky name, my guess is something in your program temporarily saves this image, and whatever is doing that isn't working.  Find out what should be saving images here, and why it isn't working.
0
 

Author Comment

by:Leprechaun
ID: 21849451
Yeah. I've checked the server and this location doesn't even exist.

I'm attaching code for the class involved below, just in case it helps. Its being called from an external class (i.e., it's in the BIN in VS.Net 2005).

I guess that means I can't step through it, right?

What if I add it to the App_Code folder, will I then be able to put a breakpoint in there?

Thanks.


using System;
using System.IO;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Data.SqlClient;
using System.Data;
using System.Web;
using System.Configuration;
using System.Drawing.Imaging;
using System.Web.Caching;
 
namespace ABC
{
	public class ImgProvider : IHttpHandler
	{
		#region IHttpHandler Members
 
		public bool IsReusable
		{
			get { return true; }
		}
 
		private string GetCacheKey(HttpContext context)
		{
			return string.Format("{0}{1}", context.Request["iid"].Replace("-", ""), context.Request["max"]);
		}
 
		public void ProcessRequest(HttpContext context)
		{
			if (string.IsNullOrEmpty(context.Request["iid"]))
				return;
 
			//caching information
			string cacheKey = GetCacheKey(context);
			string cachePath = System.IO.Path.Combine(ConfigurationManager.AppSettings["CacheFolder"], cacheKey+".jpg");
 
			//set response headers
			context.Response.Cache.AppendCacheExtension("max-age=7200,post-check=900,pre-check=3600");
			context.Response.ContentType = "image/jpeg";
 
			//if the image is found
			if (File.Exists(cachePath))
			{
				using (FileStream fs = File.OpenRead(cachePath))
				{
					const int BUFFER_SIZE = 8192;
					byte[] buffer = new byte[BUFFER_SIZE];
					int read = 0;
					while ((read = fs.Read(buffer, 0, BUFFER_SIZE)) > 0)
						context.Response.OutputStream.Write(buffer, 0, read);
					return;
				}
			}
 
			List<SqlParameter> criteriaList = new List<SqlParameter>();
			criteriaList.Add(new SqlParameter(ABC.ImageProvider.Properties.Resources.Parameter, context.Request["iid"]));
			using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings[ABC.ImageProvider.Properties.Resources.ConnectionName].ConnectionString))
			using (SqlImageStream imgRdr = new SqlImageStream(conn,criteriaList))
			{
				conn.Open();
				if (!string.IsNullOrEmpty(context.Request["max"]))
				{
					using (System.Drawing.Image img = System.Drawing.Image.FromStream(imgRdr))
					{
						int maxDimension = 1;
						try
						{
							maxDimension = int.Parse(context.Request["max"]);
						}
						catch
						{
							return;
						}
						int iMaxImgSize = Math.Max(img.Size.Width, img.Size.Height);
						double ratio = Convert.ToDouble(maxDimension) / Convert.ToDouble(iMaxImgSize);
 
						int iWidth = Convert.ToInt32(img.Size.Width * ratio);
						int iHeight = Convert.ToInt32(img.Size.Height * ratio);
 
						using (System.Drawing.Image thumb = img.GetThumbnailImage(iWidth, iHeight, new System.Drawing.Image.GetThumbnailImageAbort(ImageAbort), IntPtr.Zero))
						{
							
							thumb.Save(context.Response.OutputStream, GetCodecInfo("image/jpeg"), GetJpegParameters());
							
							//Save Thumbnail to Cache
							try
							{
								thumb.Save(cachePath, GetCodecInfo("image/jpeg"), GetJpegParameters());
							}
							catch (Exception e)
							{
							}
						}
					}
				}
				else
				{
					const int BUFFER_SIZE = 8192;
					byte[] buffer = new byte[BUFFER_SIZE];
					int read = 0;
					using (FileStream fs = File.Open(cachePath,FileMode.Create,FileAccess.Write))
					{
						while ((read = imgRdr.Read(buffer, 0, BUFFER_SIZE)) > 0)
						{
							context.Response.OutputStream.Write(buffer, 0, read);
							fs.Write(buffer,0,read);
						}
						fs.Close();
					}
					return;
				}
			}
		}
 
		private bool ImageAbort()
		{
			return true;
		}
 
		private EncoderParameters GetJpegParameters()
		{
			EncoderParameters prms = new EncoderParameters(1);
			prms.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 100L);
			return prms;
		}
 
		private ImageCodecInfo GetCodecInfo(string mimeType)
		{
			ImageCodecInfo[] infos = ImageCodecInfo.GetImageEncoders();
			foreach (ImageCodecInfo info in infos)
			{
				if (info.MimeType.CompareTo(mimeType) == 0)
					return info;
			}
			return null;
		}
 
		#endregion
	}
}

Open in new window

0
 
LVL 33

Accepted Solution

by:
raterus earned 500 total points
ID: 21849803
This looks like a problem (code snipped below).  The file is checked, but whether or not it exists, there is a ton of code after this is ran that is expecting that file to exist.

I'm not quite sure what needs to happen to fix this, but this is definitely something to look at.

You can debug any .net assembly, assuming you have the .pdb files as well.  I've never actually figured this out for myself, so if you're in a bind, I'd suggest moving the code to App_Code until you figure out the problem.


                        //if the image is found
                        if (File.Exists(cachePath))
                        {
                                using (FileStream fs = File.OpenRead(cachePath))
                                {
                                        const int BUFFER_SIZE = 8192;
                                        byte[] buffer = new byte[BUFFER_SIZE];
                                        int read = 0;
                                        while ((read = fs.Read(buffer, 0, BUFFER_SIZE)) > 0)
                                                context.Response.OutputStream.Write(buffer, 0, read);
                                        return;
                                }
                        }

Open in new window

0
 

Author Comment

by:Leprechaun
ID: 21849968
Thanks.
0
 

Author Comment

by:Leprechaun
ID: 21849990
Once I created 2 folders (d:\temp\storefront\ and d:\temp\storefront\cache\) \ the error went away. Don't know what happened in the first place, thouh.

Maybe our build process omitted those folders.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question