asp.net-coreiis

My asp.net core app doesn't find favicon.ico when it's deployed to IIS


When I run my app in Visual Studio 2017 using IIS Express, it is able to locate the favicon.ico in the wwwroot folder. When it's deployed to IIS on a server then it can't find it. I think it has to do with the URL but I don't know what the issue is, exactly.

In development the URL is https://localhost:44359. The favicon shows up OK, and if I manually type https://localhost:44359/favicon.ico then it returns it.

In production the URL is https://localhost/reporting. The favicon doesn't show up and seems to be looking for it at https://localhost/favicon.ico (which returns a 404). If I change that to http://localhost/reporting/favicon.ico then it returns the icon.

Why is it not automatically looking for the icon under the /reporting/ URL endpoint?

I have a couple of routing issues as well, but other than that the app seems to work fine. I think the routing issues may have the same cause as the favicon.


Solution

  • Browsers only check example.com/favicon.ico - they don't check in subfolders.

    If you're putting it somewhere non-standard (you are!), you'll need to point browsers to it. In the <head> of your pages:

    <link rel="shortcut icon" href="/reporting/favicon.ico">