Application_Error getting called numerous times

2019-04-14 08:41发布

问题:

I have application built on asp.net MVC3. Application runs fine but I see one issue here that on every page load Application_Error method is getting executed multiple times and the same time no exception is thrown so as such application never breaks. On debugging I could see error message but I am not able to figure out why this error is coming. I would appreciate any help.

[7/24/2011 10:30:04 PM] Error: System.Web.HttpException (0x80004005): File does not exist. at System.Web.StaticFileHandler.GetFileInfo(String virtualPathWithPathInfo, String physicalPath, HttpResponse response) at System.Web.StaticFileHandler.ProcessRequestInternal(HttpContext context, String overrideVirtualPath) 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)

回答1:

Use tool such as fiddler or firebug (on Firefox) to check the requests issued from browser and which one is getting the 404 (file not found) - that will be culprit.

Said that the most probable cause would be the request to web site icon i.e. "/favicon.ico" - most browsers issue this request to get the fav-icon for site which is typically used in address bar, bookmarks etc to easily identify the site. Its quite likely that you don't have this file under your site/project hence it generates 404 (File Not Found) error. The web development server (or IIS in certain config) uses managed pipeline to server all requests, so every request would go via global.ajax including errors for each request. Whenever you do refresh (F5) on your site, you will get the error.