by Rusty Swayne 2.September 2007 14:58
Even though this method is documented fairly well (and to be honest I don't remember where I got this code snippet) I often have people argue that they don't use asp.net themes as they break when rewritting urls. The problem stems from the fact that when the them renders by default the link tag created uses a relative path such as:
<link rel="stylesheet"
type="text/css" href="App_Themes/rustyswayne/a_normalize.css" />
and what you really need if for it to read:
<link rel="stylesheet"
type="text/css" href="/App_Themes/rustyswayne/a_normalize.css" />
You can get around this problem by Overriding the Render routine in your page. I usually do this in a BasePage class my pages inherit from:
Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
Dim ctl As Control
For Each ctl In Page.Header.Controls
If TypeOf (ctl) Is HtmlLink Then
Dim linkTag As HtmlLink = CType(ctl, HtmlLink)
If (linkTag IsNot Nothing) And linkTag.Href.StartsWith("~/") Then
If Request.ApplicationPath = "/" Then
linkTag.Href = linkTag.Href.Substring(1)
Else
linkTag.Href = Request.ApplicationPath & "/" & _
linkTag.Href.Substring("~/".Length)
End If
End If
End If
Next
End Sub