Why does the runat attribute in head-tag change the way ASP.NET handles meta tags?
Example 1:
<head>
<meta http-equiv="description" content="<%= Foo %>"/>
</head>
Renders
<meta http-equiv="description" content="Bar"/>
Example 2:
<head runat="server">
<meta http-equiv="description" content="<%= Foo %>"/>
</head>
Renders:
<meta http-equiv="description" content="<%= Foo %>"/>
Note the inconsistency, <
became <
, but >
remains the same.
There are some questions on this topic and the answers are workarounds, but no one seems to know why this is happening.
a source to share
You cannot have a script tag (<% =%>) inside a server control, so instead of executing it, it turned into plain text.
You can add a meta tag from code located like this:
HtmlMeta meta = new HtmlMeta();
meta.HttpEquiv = "description";
meta.Content = Foo;
Page.Header.Controls.Add(meta);
a source to share
When you add a runat = server, the Head tag becomes server-side. I assume from your results that the content of the server controls is not parsed for inline lookups using the <% ...%> syntax.
You can also make a server control meta tag by adding the runat = server to it and programmatically accessing its attributes.
a source to share