Error in global asax: file does not exist

I am trying to understand what happened with the error that sent me to the OnArror global handler for ASAX.

using System; using System.Web; namespace GLSS.Components.HttpModules { public class ExceptionModule : System.Web.IHttpModule { private void OnError(object sender, EventArgs e) { HttpContext context = HttpContext.Current; //get the last error Exception ex = context.Server.GetLastError(); if(ex.InnerException.GetType().ToString() == "CSLA.DataPortalException") ex = ex.InnerException; 

Here is my exception converted to string

 HttpContext.Current.Server.GetLastError().Message "File does not exist." HttpContext.Current.Server.GetLastError().StackTrace " 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)" 

How to determine which line of code is causing this error? I tried to disable Debug options when an error occurred, but it is not, I still ended up in the global ONERROR handler.

It's one thing that I see that the code assumes that there will be an Internal exception, and it looks like NULL and causes a second error in the handler.

I assume that the error occurs somewhere in the compiled code. I checked Web.Config and the only paths mentioned here are the path to the log and it seems valid and the logging works.

Update I found additional information here:

How to solve the exception "File does not exist"?

When I check this in the Immediate window:

 ? HttpContext.Current.Request.Url.ToString() "http://localhost:2322/favicon.ico" 

However, what puzzles me is that I'm looking for all of my solution looking for favicon.ico using "Find Files" and I don't see the link.

Why am I getting an error that the icon file was not found when I cannot see the link to it? I assume the assembly uses it? But why is he looking for it in the root web server?

+7
source share
1 answer

The request for favicon.ico is blindly made by most modern browsers, and they expect 404 (File not found) if there is no icon (this is the correct behavior). Below you can find a quote from the HTML5 working draft about the link type "icon"

If there is no link with the icon keyword for received documents via HTTP or HTTPS, user agents may instead try to retrieve and use the icon with the absolute URL obtained by resolving the URL /favicon.ico with respect to the document address, as if the page had announced that the icon uses the icon keyword.

The reason you see the exception is because a web development server or IIS configured to use Managed / Integrated Pipeline Mode puts all requests through Global.asax (including errors).

You can try to prevent browsers from executing queries by creating the following dummy link for the icon:

 <html> <head> <link rel="shortcut icon" href="#" /> ... </head> ... </html> 

You can also try the following:

  • Add the following line at the beginning of the RegisterRoutes method:

    routes.IgnoreRoute("favicon.ico");

    or even more advanced version:

    routes.IgnoreRoute("{*favicon}", new { favicon=@ "(.*/)?favicon.ico(/.*)?"});

  • Create an empty file for favicon
  • Filter the errors by checking HttpException.GetHttpCode() for 404 and ((System.Web.HttpApplication)Sender).Context.Request.Url for /favicon.ico.
+15
source

All Articles