Application_error function intermittently catch "File does not exist"
I am using the Application_Error
event for handling the exceptions and it catches almost all exceptions correctly. However in some pages it catches with exception "File does not exist" and I am not able to find from where it exactly occurs. When I comment the Application_Error
code, surprisingly that web page works fine.
My main conc开发者_运维问答ern is how can trace back to the line of code from where it threw to Application_Error
function.
Use HttpContext.Current.Request.Url.ToString()
to look at the file path of the missing file.
hoooo....... just now solved my issue. During my debugging I had put one checkpoint in Appilcation_Error code and when execution reached it I could see the path of an image (path was wrong) which was loading at that time and which causes the exception. :)
Right in my case also in Jquery at lots of place used backgroung image uri & that did not exist, thats why this type of error.
To see the problem, on Application_Error event of Global.asax put:
public void Application_Error(object sender, EventArgs e) {
// Code that runs when an unhandled error occurs
Exception ex = Server.GetLastError();
Console.WriteLine("Application_Error() -> " + ex.Message + "\n\nURL: " + HttpContext.Current.Request.Url, ex);
if (ex is HttpUnhandledException)
Context.ClearError(); // System.NullReferenceException
}
精彩评论