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

Viewed 9325

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...

in development the url is https://localhost:44359 The favicon show up 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.

Can someone please suggest why it's not automatically looking for the icon under /reporting/ ??

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.

2 Answers

There is an issue with finding static resources for applications that are in subfolders of a website. However, in Razor pages, in the <head> you can use:

<link rel="shortcut icon" href='@Url.Content("~/favicon.ico")'>

where the ~ refers to your application's wwwroot folder.

Related