I\'m trying to add and set favicon.ico.
When I saw a initial project that Visual Studio 2017 make automatically, the favicon.ico
file is just in the w
wwwroot/index.html file has the link to favicon.
<link rel="icon" type="image/x-icon" href="favicon.ico">
is the code to add favicon to the website.
For .net core Single Page Application (SPA) project the favicon will be rendered from its own respective static file. For example if are using angular as client application there is index.html
file inside src
and in index.html
you can link your favicon with following code
<link rel="icon" type="image/x-icon" href="favicon.ico">
In _Layout.cshtml include,
<link rel="shortcut icon" href="//.../content/images/favicon.ico" />
Just a headsup for anyone struggling with this issue. If you're serving up a spa from .net core 2 (angular, react, other) sometimes the spa will look under the spa's static file's folder. I struggled with for awhile and found that the only way i could get the favicon to show up with my angular app was to put the favicon and site.webmanifest in my app/assets folder. Worked without any modification after that. There are some suggestions out there to modify the content response types but didn't have to do that as long as the files were in the right folder. Hopefully this helps someone else.
If your favicon.ico file is in wwwroot folder and if you are still getting 404 error when browser try to get favicon.ico, make sure you have app.UseStaticFiles();
in your Startup.cs -> public void Configure(IApplicationBuilder app, IHostingEnvironment env)
.
Please read Static files in ASP.NET Core for detail.
If you add favicon.ico in wwwroot and not in any subfolder, you don't need to add the <link ...
tag in your html or cshtml.