为什么head-tag中的runat属性会更改ASP.NET中处理meta标签的方式? [英] Why does the runat-attribute in the head-tag change the way meta tags are handled in ASP.NET?
本文介绍了为什么head-tag中的runat属性会更改ASP.NET中处理meta标签的方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
示例1:
<head>
<meta http-equiv="description" content="<%= Foo %>"/>
</head>
渲染器
<meta http-equiv="description" content="Bar"/>
示例2:
<head runat="server">
<meta http-equiv="description" content="<%= Foo %>"/>
</head>
渲染器:
<meta http-equiv="description" content="<%= Foo %>"/>
请注意差异,<
变为& lt;
,但>
保持不变.
Note the discrepancy, the <
has become <
but the >
remains the same.
有一些
There are some questions on this topic, and the answers are the workarounds, but nobody seems to know why this happens.
推荐答案
在服务器控件中不能包含脚本标记(<%=%>),这就是为什么它会变成纯文本而不是被执行的原因.
You can't have a script tag (<% = %>) inside a server control, that's why it's turned into plain text instead of being executed.
您可以像这样从后面的代码中添加meta标记:
You can add the meta tag from the code behind like this:
HtmlMeta meta = new HtmlMeta();
meta.HttpEquiv = "description";
meta.Content = Foo;
Page.Header.Controls.Add(meta);
这篇关于为什么head-tag中的runat属性会更改ASP.NET中处理meta标签的方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文