Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 767
RazorUK84 Avatar asked Jul 11 '17 14:07

RazorUK84


2 Answers

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">
like image 104
ceejayoz Avatar answered Nov 14 '22 03:11

ceejayoz


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.

like image 36
PeterF Avatar answered Nov 14 '22 02:11

PeterF