[c#] How to add favicon.ico in ASP.NET site

The solution structure of my application is:

enter image description here

Now I am in Login.aspx and I am willing to add favicon.ico, placed in the root, in that page.

What I am doing is:

<link id="Link1" runat="server" rel="shortcut icon" href="../favicon.ico" type="image/x-icon" />  
<link id="Link2" runat="server" rel="icon" href="../favicon.ico" type="image/ico" /> 

Also I have tried:

<link id="Link1" runat="server" rel="shortcut icon" href="favicon.ico" type="image/x-icon" />  
<link id="Link2" runat="server" rel="icon" href="favicon.ico" type="image/ico" /> 

But these aren't working.

I have cleared the browser cache but no luck.

What will be the path to the favicon.ico from:

  • Login.aspx
  • Site.master

Thank you.


The login page's URL: http://localhost:2873/Pages/Login.aspx and the favicon.ico's URL: http://localhost:2873/favicon.ico.

I am unable to see the favicon.ico enter image description here after changing my code as:

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

This question is related to c# asp.net favicon

The answer is


Check out this great tutorial on favicons and browser support.


resolve the url like this href="<%=ResolveUrl("~/favicon.ico")%>"


@Scripts.Render("~/favicon.ico"); Please try above code at the bottom of your Layout file in MVC


for me, it didn't work without specifying the MIME in web.config, under <system.webServer><staticContent>

<mimeMap fileExtension=".ico" mimeType="image/ico" />

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

This worked for me. If anyone is troubleshooting while reading this - I found issues when my favicon.ico was not nested in the root folder. I had mine in the Resources folder and was struggling at that point.


    <link rel="shortcut icon" href="@Url.Content("~/images/")favicon.ico" type="image/x-icon"/ >

This works for me in MVC4 application favicon image is placed in the images folder and it will traverse from root directory to images and find favicon.ico bingo!


I have the same issue. My url is as below

http://somesite/someapplication

Below doesnot work

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

I got it to work like below

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

Simply:

/favicon.ico

The leading slash is important.


Examples related to c#

How can I convert this one line of ActionScript to C#? Microsoft Advertising SDK doesn't deliverer ads How to use a global array in C#? How to correctly write async method? C# - insert values from file into two arrays Uploading into folder in FTP? Are these methods thread safe? dotnet ef not found in .NET Core 3 HTTP Error 500.30 - ANCM In-Process Start Failure Best way to "push" into C# array

Examples related to asp.net

RegisterStartupScript from code behind not working when Update Panel is used You must add a reference to assembly 'netstandard, Version=2.0.0.0 No authenticationScheme was specified, and there was no DefaultChallengeScheme found with default authentification and custom authorization How to use log4net in Asp.net core 2.0 Visual Studio 2017 error: Unable to start program, An operation is not legal in the current state How to create roles in ASP.NET Core and assign them to users? How to handle Uncaught (in promise) DOMException: The play() request was interrupted by a call to pause() ASP.NET Core Web API Authentication Could not load file or assembly 'CrystalDecisions.ReportAppServer.CommLayer, Version=13.0.2000.0 WebForms UnobtrusiveValidationMode requires a ScriptResourceMapping for jquery

Examples related to favicon

Add Favicon with React and Webpack What is the best practice for creating a favicon on a web site? HTML 5 Favicon - Support? How can I get a favicon to show up in my django app? How to set-up a favicon? Favicon not showing up in Google Chrome Add image in title bar How to set custom favicon in Express? Why does my favicon not show up? Correct MIME Type for favicon.ico?