Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ElmahCore in ASPNET Core 7 Web API throws 404 /favicon.ico Not Found error... #172

Open
tnfoundry opened this issue Jun 2, 2023 · 6 comments

Comments

@tnfoundry
Copy link

ElmahCore implement via NuGet for an ASPNET Core 7 Web API throws the error below.

Anyone have any suggestions on how to correct as for each error received?

Is a favicon missing in ElmahCore source?

image

@afastrunner
Copy link

afastrunner commented Jun 3, 2023

These are the errors that YOUR site has raised that were caught by ElmahCore. If your site doesn't have a favicon.ico browsers automatically try to load one when they go to a domain. which will raise a 404 error.

Do you really want to log all 404 errors?
I think a lot of us filter out 400 errors something like:

 public class CmsErrorLogFilter : IErrorFilter
    {
        public void OnErrorModuleFiltering(object sender, ExceptionFilterEventArgs args)
        {
            if (args.Exception.GetBaseException() is FileNotFoundException)
                args.Dismiss();

            if (args.Context is HttpContext httpContext)
            {
                if (httpContext.Response.StatusCode == 404)
                    args.Dismiss();

                if (httpContext.Response.StatusCode == 400)
                    args.Dismiss();
            }
        }
    }

@tnfoundry
Copy link
Author

@afastrunner - thank you, I did not say ElmahCore was the issue, but trying to understand. I don't maintain the source code for the route .../elmah/errors. The is a generated route from the ASPNET Core config. It appears that the /elmah/errors route is attempting to reference favicon.ico from its generated Elmah log error user interface that is shown the original posting. Can you explain how or where the ElmahCore admin interface is generated from?

@afastrunner
Copy link

when your browser goes to localhost:7065/elmah/errors the browser says to it's self "lets see if this domain localhost has a favicon.ico I can display in the browser tab and requests it from /favicon.ico" the /favicon.ico request starts with / so it's made to the root application localhost:7065/favicon.ico which is your application, the static file middleware there says "nope I don't have favicon.ico and raises a 404 exception" elmah middleware sees the 404 exception and logs it's in the interface your seeing.
Adding a favicon.ico in the elmah/errors location wouldn't prevent this.
So it goes back to to what you want to do, ether have 404 error messages logged or not. OR add a favicon.ico to the /wwwroot folder in your application to prevent this one 404 error OR I guess if you really wanted to you could add a middleware that look for requests to /favicon.ico and returns 200 (but that would be odd)

@tnfoundry
Copy link
Author

@afastrunner - thank you for your time to explain. And that it my understanding of what is going on too, but the confusion comes from the fact that dropping a favicon on the root of localhost:7065 had no affect when I tried before submitting this issue to GitHub. Plus I never realized that a browser always tries request a favicon.ico even if there isn't page containing meta data link/referencing one. Surprised I've never ran into that.

You mention a wwwroot folder, but my root are just libraries and does not have wwwroot. I guess I give that a try

@afastrunner
Copy link

Yeah if it's WebAPI you likely don't have Static files Middleware enabled so putting favicon.ico in your root doesn't serve anything. If it was a MVC/Razor you would have a wwwroot folder and static files middleware serving files from that folder.
Best bet is just ignore that error or specifically filter it out in IErrorFilter

@tnfoundry
Copy link
Author

Many thanks for taking the time to help assist with this. Much appreciated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants