.net2.0 正式版中怎么控制Meta中的元素?

lnwuyaowei 2006-01-17 08:17:43
如题,在beta版中的
this.Header.Metadata.Add("taye", "value");
不能用了。
...全文
178 8 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
BingGroup 2006-03-20
  • 打赏
  • 举报
回复
我也遇到这个问题呀,怎么解决?
lnwuyaowei 2006-02-06
  • 打赏
  • 举报
回复
up
stpangpang 2006-02-04
  • 打赏
  • 举报
回复
mark
lnwuyaowei 2006-02-04
  • 打赏
  • 举报
回复
up
kill3434 2006-01-27
  • 打赏
  • 举报
回复
mark
lnwuyaowei 2006-01-27
  • 打赏
  • 举报
回复
再up.
lnwuyaowei 2006-01-18
  • 打赏
  • 举报
回复
up
lnwuyaowei 2006-01-17
  • 打赏
  • 举报
回复
# re: ASP.NET 2.0 backwards compatible? NOT. Here's an obvious one - level 200
posted at Tuesday, August 17, 2004 3:32 AM by Anders Norås
The head element in the ASP.NET 2.0 page template is by default declared to run at the server. In addition the System.Web.UI.HtmlControls namespace has a new class called HtmlHead defined. When you set the id attribute of the head element to “Head” this becomes a member of your class (which inherits from System.Web.UI.Page).
The reason for you not seeing the code defining this member is that ASP.NET 2.0 uses partial classes to separate user defined code from tool generated code.
As a result of this you get a member naming conflict when defining an additional member called “Head” typed System.Web.UI.HtmlControls.HtmlGenericControl.

To solve your problem using your existing code which I reckon is similar to this:
ASPX snippet:
<head id="Head" runat="server">

Codebehind snippet:
protected HtmlGenericControl Head;
private void Page_Load(object sender, System.EventArgs e)
{
HtmlGenericControl meta=new HtmlGenericControl("meta");
meta.Attributes.Add("name","pragma");
meta.Attributes.Add("content","no-cache");
Head.Controls.Add(meta);
}

Remove the declaration of the “Head” member in the code behind file.

Another option is to add your metadata using the Page.Header.Metadata collection like this:
Page.Header.Metadata.Add("name", "pragma");
Page.Header.Metadata.Add(“content”,”no-cache”):
=====================================================
调试后得到的结果如下:
<head><link href="../App_Themes/White/aboutMenu.css" type="text/css" rel="stylesheet" /><link href="../App_Themes/White/Default.css" type="text/css" rel="stylesheet" /><title>
Untitled Page
</title><meta name="robots" content="all" /><link rel="Shortcut Icon" href="../favicon.ico" /><meta name="pragm" content="no-cache"></meta><style type="text/css">
.ctl00_Menu2_0 { background-color:white;visibility:hidden;display:none;position:absolute;left:0px;top:0px; }
.ctl00_Menu2_1 { text-decoration:none; }
.ctl00_Menu2_2 { }

</style></head>

这个是正确的答案么?


62,248

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧