母版页元标记正在胜过子页元标记
我想知道是否有办法更改特定页面上的元描述,但保留我未指定任何信息的页面的母版页中的元数据。 我正在尝试这种方法:
HtmlHead headTag = (HtmlHead)this.Header;
HtmlMeta pageMetaTag = new HtmlMeta();
pageMetaTag.Name = "Description";
pageMetaTag.Content = "Test";
headTag.Controls.Add(pageMetaTag);
它正确地添加了描述标签,但我想同时从母版页中删除/禁用元标签。 这可能吗? 提前致谢,祝您有美好的一天。
I want to know if there is way to change meta description on specific pages, but to keep the meta data from the master page for the pages where I haven't specified any info.
I am trying this approach:
HtmlHead headTag = (HtmlHead)this.Header;
HtmlMeta pageMetaTag = new HtmlMeta();
pageMetaTag.Name = "Description";
pageMetaTag.Content = "Test";
headTag.Controls.Add(pageMetaTag);
Which adds the description tag properly, but I want in same time to remove/disable the meta tag from the master page.
Is that possible?
Thanks in advance and have a nice day.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Meta标签属于http标头。在主内容页面设计中,它们通常是母版页的一部分。但这不是必需的! 您可以将 ContentPlaceHolder 集成到母版页的标题部分。通过这种方法,您可以轻松地在内容页面中设置元标记和其他标题元素。
如果您需要元标记默认值,则可以引入具有两个嵌套母版页的设计,其中外部母版页包含标题的 ContentPlaceHolder,内部母版页包含默认标题。
Meta tags belongs to http headers. In a master-content page design they are usually part of the master page. But this isn’t required! You can integrate a ContentPlaceHolder into the header section of the master page. With this approach you can easily set meta tags and other header elements in content pages.
If you need meta tag defaults, you can introduce a design with two nested master pages, where the outer master page contains the ContentPlaceHolder for the header and the inner master page contains the default header.