Setting ASP.NET Core 2.0 favicon

前端 未结 4 851
感动是毒
感动是毒 2021-02-19 07:17

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

相关标签:
4条回答
  • 2021-02-19 07:31

    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">
    
    0 讨论(0)
  • 2021-02-19 07:32

    In _Layout.cshtml include,

    <link rel="shortcut icon" href="//.../content/images/favicon.ico" />
    
    0 讨论(0)
  • 2021-02-19 07:41

    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.

    0 讨论(0)
  • 2021-02-19 07:44

    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.

    0 讨论(0)
提交回复
热议问题