Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to solve exception "File does not exist"?

I have a basic ASP.NET MVC2 site which logs a single "File does not exist" error every time a view (not partial views) is loaded. I am pretty sure this is because I am referencing a file, from the master page, that does not exist, but I cannot figure out which one it is.

The stack trace is not useful (see below). Does anyone have any tips on how to best debug this?

File does not exist. :    at System.Web.StaticFileHandler.GetFileInfo(String virtualPathWithPathInfo, String physicalPath, HttpResponse response)
   at System.Web.StaticFileHandler.ProcessRequestInternal(HttpContext context)
   at System.Web.DefaultHttpHandler.BeginProcessRequest(HttpContext context, AsyncCallback callback, Object state)
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
like image 481
Øyvind Avatar asked Sep 13 '10 23:09

Øyvind


People also ask

Why does file not exist in Python?

Python raises this error because your program cannot continue running without being able to access the file to which your program refers. This error is usually raised when you use the os library. You will see an IOError if you try to read or write to a file that does not exist using an open() statement.

Which Python exception will be raised if the user attempts to open a non existent file?

Opening a Non-Existent File. Using the built-in open function, you can try to open a file for reading (more on open in the next section). But the file doesn't exist, so this raises the IOError exception.


1 Answers

As you say, its probably a missing file or image referenced by your master page. To capture the error, add the following error handler to your Global.asax

protected void Application_Error(object sender, EventArgs e)
{
    Exception ex = Server.GetLastError();

    if (ex.Message == "File does not exist.")
    {
        throw new Exception(string.Format("{0} {1}", ex.Message, HttpContext.Current.Request.Url.ToString()), ex);
    }
}

This should then tell you what resource the page is requesting

like image 165
Clicktricity Avatar answered Oct 21 '22 20:10

Clicktricity