Broken links from .axd file

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.
LeprechaunAsked:
Who is Participating?
 
raterusCommented:
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
 
raterusCommented:
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
 
LeprechaunAuthor Commented:
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
 
LeprechaunAuthor Commented:
Thanks.
0
 
LeprechaunAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.