This post originated from an RSS feed registered with .NET Buzz
by Peter van Ooijen.
Original Post: Response.AppendHeader, Webforms and favicons
Feed Title: Peter's Gekko
Feed URL: /error.htm?aspxerrorpath=/blogs/peter.van.ooijen/rss.aspx
Feed Description: My weblog cotains tips tricks and opinions on ASP.NET, tablet PC's and tech in general.
Perhaps I'm too naive on this but I'm stuck. Having turned the web upside down twice I'm still completely puzzled.
In the header of an aspx page's response is some meta-information to help the browser. One of the headers can be the stylesheet to use when rendering the page. Having linked a stylesheet in the webform designer (Format|Document styles in VS 2003) your page header will look something like this.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > <HTML> <HEAD> <title>Onderwijs</title> <meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR"> <meta content="C#" name="CODE_LANGUAGE"> <meta content="JavaScript" name="vs_defaultClientScript"> <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema"> <LINK href="StyleSheetIndato.css" type="text/css" rel="stylesheet"> </HEAD> <body>
Linking a stylesheet this way has two disadvantages
You have to repeat it for every page in the application
It is hard to maintain, switching style sheets requires editing all aspx files
Being an OOP guy I consider the best way to link the sheet is in my page base class. The Response object has an AppendHeader method, so this could be a nice way to set the stylesheet:
The code tries to add a header to the response which contains the link to the stylesheet.
Alas this does not work. In all my tries the AppendHeader method does nothing at all when the response is rendered by a webform. And I've found no nice event to hook into or method to override. I had this frustration before, at the time the solution was to wrestle in the stylesheet link in the page body pretending it was a snippet of script.
I'm still doing that, but recently revisited the subject and gave it another try. Another thing to put in a header is a shortcut icon, which is used in the browser's toolbar and favorites.
This looks simple, but neither VS 2003 nor VS 2005 accepts even the markup. Let alone anything like Response.AppendHeader or injecting the link in the body will work.
As we say in Dutch it's giving me a pointed head. Any suggestion is more than welcome