Secret to Unique FavIcon.ico files in DotNetNuke

Well, it was a secret to me until yesterday anyhow.

If you are running a DotNetNuke installation with multiple portals, you may have noticed that even if you replace the FavIcon.ico file in the root of the application, you get the same FavIcon.ico file displaying for all of your portals.  And, even if you have just one portal and upgrade the portal and forget to not copy the FavIcon.ico file up, of course you’ll have to recopy the one you want back up.

So, while I was trying to track down another problem yesterday, I was in the Default.aspx.vb file of the 4.8 release of DotNetNuke when I notice these lines:

Private Sub ManageFavicon()
    Dim strFavicon As String = _        CType(DataCache.GetCache("FAVICON" & _        PortalSettings.PortalId.ToString), String)
    If strFavicon = "" Then
        If File.Exists(PortalSettings.HomeDirectoryMapPath & _            "favicon.ico") Then
            strFavicon = PortalSettings.HomeDirectory & "favicon.ico"
            If Not Common.Globals.PerformanceSetting = _                Common.Globals.PerformanceSettings.NoCaching Then
                DataCache.SetCache("FAVICON" & _                    PortalSettings.PortalId.ToString, strFavicon)
            End If
        End If
    End If
    If strFavicon <> "" Then
        Dim objLink As New HtmlLink()
        objLink.Attributes("rel") = "SHORTCUT ICON"
        objLink.Attributes("href") = strFavicon
    End If
End Sub


Check it out!  It’s looking for a favicon.ico file in the portal’s directory (ie, portal/0, portal/1, etc) and if it finds it it is inserting

<link rel=”SHORTCUT ICON” href=”path to portal favicon.ico here” />

into the HEAD of the page.

This means that every portal can have a unique icon associated with it.  Cool!

Related Post

Leave a Reply

Comment Policy:

  • You must verify your comment by responding to the automated email that is sent to your email address. Unverified comments will never show.Leave a good comment that adds to the conversation and I'll leave your link in.
  • Leave me pure spam and I'll delete it.
  • Leave a general comment and I'll remove the link but keep the comment.

Notify me of followup comments via e-mail