Diagnose ‘File does not exist’ error in ASP.net

I have ventured deep into the land of asp.net the past few months.  Luckily the the blogsphere keeps me on track.  Every day or so I run into a nagging issue with asp.net or something I can’t quite accomplish.  I have been nearing the end of my project and have simply had a bug which I could not fix.  It seems asp.net will fire an error when ANY file is missing on an asp.net webpage.  This is incredibly difficult to diagnose since the error does not contain the file that is missing!  See below for an example

MESSAGE: File does not exist.
SOURCE: System.Web
QUERYSTRING: 695777780
TARGETSITE: Void ProcessRequestInternal(System.Web.HttpContext)
STACKTRACE: at System.Web.StaticFileHandler.ProcessRequestInternal(HttpContext context)…

Catching the error is accomplished by hooking into the Application_Error event typically in the global.asax

void application_Error(object sender, EventArgs e)


K# offered a great post on just how he went about solving this issue. Basically setting a breakpoint at the above section of code to see the error when it happens. That isn’t quite enough, you’ll notice visually studio even in the watched variables has nothing that leads to the missing file. If you add a watch to ((HttpApplication)sender).Context.Request you will quickly see the exact file causing the error message.

My ultimate solution was to add the ((HttpApplication)sender).Context.Request.FilePath in all my global error logging so the file that is missing is always included in the error message.

Be Sociable, Share!


No comments yet, be the first.

Add a Comment