Solved

Broken links from .axd file

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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 …
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

708 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now