Do you ever have those days when you are writing code and everything is going great and then all of a sudden some little thing crops up and before you know it you have lost a half day trying to figure out one little thing?

Well today was one of those days for me. It has still been productive but it could have been so much more so. If only I had thought to pull out Fiddler earlier, I would have saved a lot of hair pulling and if you know me you know there is not any hair to pull.

Anyway, read on for more info on Fiddler and how it saved my bacon.

So I am working on an Image Management library for a client of a client at the moment and as per usual it involves uploading of images. Not just one but multiple images and as is always the case with image management you want to make it as easy as possible.

In the past I have used swfobject with good results but this time round I wanted to improve on the experience and wrap up the code much neater.

So I did some googling and the hunt was on for a jQuery multiple file upload control.

Enter Uploadify. Check out their website over here. I will be making a donation to these guys as soon as I get paid from this job cause it’s a nice implementation.

Underneath the hood it still uses swfobject and wraps it all up nicely with jQuery. One problem I did have with it however was the ‘uploadifySettings’ function did not work and I suspect this is either because it was developed with an older version of jQuery and/or Flash. Not a problem though, this was easy to work around.

The real problem I had started when I was trying to actually do an upload. It was not a jQuery problem, it was not a Flash problem, it was not an Uploadify problem. It was my problem and it was a difficult one to debug.

I was getting HTTP Error 500 or Error Code #2308 and I could not figure out why.

I checked all my paths: Fine

I checked IIS Permissions: Fine

I checked and rechecked file names and locations: All Fine.

The problem was in the end in my upload.ashx file and it took Fiddler to figure this one out.

The problem was as follows with my Upload.ashx file looking like this

<%@ WebHandler Language="C#" CodeBehind="Upload.ashx.cs" Class="ImageLibrary.Upload" %>

Notice the class name has ImageLibrary as the namespace. My code behind looked like this:

using System.IO; using System.Web; using System.Web.SessionState; publicclass Upload : IHttpHandler, IRequiresSessionState { public Upload() { } publicvoid ProcessRequest(HttpContext context) { HttpPostedFile file = context.Request.Files["Filedata"]; string targetFilePath = string.Format("{0}{1}{2}", context.Request.PhysicalApplicationPath, context.Request["folder"], file.FileName); file.SaveAs(targetFilePath); context.Response.Write("1"); } publicbool IsReusable { get { returnfalse; } } }

Woops! No Namespace.

Now everything compiled just fine. Everything looked ok but it just failed with Error 500. Now because this was posting to an .ashx file I didn’t see what the problem was.

I scoured the IIS logs and I could see it was doing a POST but throwing error 500:

2010-07-09 05:31:46 127.0.0.1 POST /Scripts/Upload.ashx – 80 – 127.0.0.1 Shockwave+Flash 500 0 0 19

2010-07-09 05:33:15 127.0.0.1 POST /Scripts/Upload.ashx – 80 – 127.0.0.1 Shockwave+Flash 500 0 0 48146

Then all of a sudden I remembered Fiddler and within 30 seconds my problem was solved.

I tried the upload again with Fiddler running and straight away I could see the problem.

Fiddler

As you can see once I used Fiddler I had a visual on what Error 500 actually meant on the server.

Awesome!

BondiGeek