Problem with adding favicon to blazor server

Saeed Pooladzadeh 251 Reputation points
2023-04-26T07:21:29.5566667+00:00

Hello, I want to insert a link for the site favicon in the layout. C HTML, my link is:

<link rel="icon" type="image/x-icon" href="wwwroot/favicon.ico">

but I get this error: Untitled1

But as you can see my favicon is in the wwwroot folder: Untitled2

Do you think what is wrong? regards, Saeed

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,345 questions
Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,477 questions
0 comments No comments
{count} votes

Accepted answer
  1. Xinran Shen - MSFT 2,091 Reputation points
    2023-04-26T08:09:07.8566667+00:00

    Hi @Saeed Pooladzadeh

    From your error message, The project will find the favicon.ico in the path of ...\wwwroot\wwwroot\favicon.ico , But your favicon.ico just under the wwwroot folder, So you need to change your code like:

    <link rel="icon" type="image/x-icon" href="/favicon.ico">

    href will default find file under wwwroot folder, you don't need to add wwwroot in the path manually.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best regards,

    Xinran Shen

    2 people found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Timo Kinnunen 126 Reputation points
    2023-05-29T18:20:30.7566667+00:00
    Blazor web app
    
    create a my-logo.svg-file from your my-logo.png-file (1000 pixels x 1000 pixels or less)
    
    copy it here:
    <head>
    ...
    	<link rel="icon" href="images/my-logo.svg">
    </head>
    
    
    0 comments No comments