Solved

Broken links from .axd file

Posted on 2008-06-23
5
349 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
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…

740 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