Search This Blog

Thursday, August 11, 2011

How to add dynamic fevicon to your websites in asp.net page or master page


How  to add fevicon to your websites in asp.net page or master page. It is so simple. 
follow the below steps.

1) First you need to create a 16 * 16 px icon (if you give more size also it will accept but finally it will convert to 16 * 16 px only) and name it as favicon.ico (name may be anything and format either .ico or .jpg).

if you want to convert your images to icon click here.




2) Save your favicon to the root directory of your ASP.Net web application like above image.

3) For the latest versions of Firefox, Internet Explorer and Chrome, however, you need to add two links to your favicon to the head in your HTML.

Default.aspx:
 
<head> <title>My Websitetitle>  

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

head>
   
Note:  Why 2 links are required - to work in all the browsers

For dynamic fevicon:

.aspx

<head> <title>My Websitetitle>  

<link runat="server" rel="shortcut icon" href="" type="image/x-icon"/>
<
link runat="server" rel="icon" href="" type="image/ico"/>

head>

.aspx.cs:


 protected void Page_Load(object sender, EventArgs e)
    {
        Link1.Attributes.Add("href", "favicon.ico");
        Link1.Attributes.Add("href", "favicon.ico");
    }

Final output looks like below image:






Popular Posts