Solved

Broken links from .axd file

Posted on 2008-06-23
5
346 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

808 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