关于sharepoint 的如何动态写Meta部分的内容
2008-09-10 02:29
351 查看
我想应该用不同的方法,我想以下应该是其中一种
My approach would be to create a special render control and generate the required HTML code via the control.
1) Create a render control and override the RenderFieldForDisplay method. For an example, see http://msdn2.microsoft.com/en-us/library/aa981226.aspx. This article shows also how to create the custom edit mode but you don't need all of it.
Deploy the custom control as mentioned in the article.
2) Add the contentplaceholder in the master page (as you already tried), or use the default <asp:ContentPlaceHolder id="PlaceHolderAdditionalPageHead" runat="server"/>
Place this in the <head> section, right after the <title> tag for example.
3) Call the custom control to render the meta description field in the page layout:
<asp:Content ContentPlaceholderID="PlaceHolderAdditionalPageHead" runat="server">
<PublishingWebControls:EditModePanel runat="server" id="displayModeMetadata" PageDisplayMode="Display" SuppressTag="true">
<Mytag:HeadMetadataFieldControl FieldName="MyMetadatafieldname" runat="server"></Mytag:HeadMetadataFieldControl>
</PublishingWebControls:EditModePanel>
</asp:Content>
Hope this is clear enough.
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
using System.Data;
namespace MyControls
{
public class KeywordsTag: UserControl
{
public override void RenderControl(HtmlTextWriter writer)
{
//Get the sp file context and retrieve corresponding field
try
{
SPFile file = SPContext.Current.File;
String keywords = file.Item["Keywords"].ToString();
//read the keywords field and render
writer.Write("<meta name=\"keywords\" content=\"" + keywords + "\" />");
}
catch { }
base.RenderControl(writer);
}
}
}
Build your user control library and add a Tag prefix in your master page.
<%@ Register Tagprefix="MyTag" Namespace="MyControls" Assembly="AssemblyName, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1b25d240d1396f63" %>
Note: The Assembly Name , Version, Culture and PublicToken have to be changed to your Assembly Name , Version, Culture and PublicToken
On your master page add the control before the title tag as below:
<MyTag:KeywordsTag runat="server" />
Your pages derived from the modified master page will show the meta keywords tag.
This assumes that you are using the Field Named "Keywords" to store your keywords. If you are using a field like "mykeywords" change your user control accordingly.
My approach would be to create a special render control and generate the required HTML code via the control.
1) Create a render control and override the RenderFieldForDisplay method. For an example, see http://msdn2.microsoft.com/en-us/library/aa981226.aspx. This article shows also how to create the custom edit mode but you don't need all of it.
Deploy the custom control as mentioned in the article.
2) Add the contentplaceholder in the master page (as you already tried), or use the default <asp:ContentPlaceHolder id="PlaceHolderAdditionalPageHead" runat="server"/>
Place this in the <head> section, right after the <title> tag for example.
3) Call the custom control to render the meta description field in the page layout:
<asp:Content ContentPlaceholderID="PlaceHolderAdditionalPageHead" runat="server">
<PublishingWebControls:EditModePanel runat="server" id="displayModeMetadata" PageDisplayMode="Display" SuppressTag="true">
<Mytag:HeadMetadataFieldControl FieldName="MyMetadatafieldname" runat="server"></Mytag:HeadMetadataFieldControl>
</PublishingWebControls:EditModePanel>
</asp:Content>
Hope this is clear enough.
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
using System.Data;
namespace MyControls
{
public class KeywordsTag: UserControl
{
public override void RenderControl(HtmlTextWriter writer)
{
//Get the sp file context and retrieve corresponding field
try
{
SPFile file = SPContext.Current.File;
String keywords = file.Item["Keywords"].ToString();
//read the keywords field and render
writer.Write("<meta name=\"keywords\" content=\"" + keywords + "\" />");
}
catch { }
base.RenderControl(writer);
}
}
}
Build your user control library and add a Tag prefix in your master page.
<%@ Register Tagprefix="MyTag" Namespace="MyControls" Assembly="AssemblyName, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1b25d240d1396f63" %>
Note: The Assembly Name , Version, Culture and PublicToken have to be changed to your Assembly Name , Version, Culture and PublicToken
On your master page add the control before the title tag as below:
<MyTag:KeywordsTag runat="server" />
Your pages derived from the modified master page will show the meta keywords tag.
This assumes that you are using the Field Named "Keywords" to store your keywords. If you are using a field like "mykeywords" change your user control accordingly.
相关文章推荐
- Visual Studio 2017中使用正则修改部分内容 如何使用ILAsm与ILDasm修改.Net exe(dll)文件 C#学习-图解教程(1):格式化数字字符串 小程序开发之图片转Base64(C#、.Net) jquery遍历table为每一个单元格取值及赋值 。net加密解密相关方法 .net关于坐标之间一些简单操作
- 分布式下的爬虫Scrapy应该如何做-关于动态内容js或者ajax处理(2)
- 关于如何设定css样式使得文本溢出部分用省略号代替
- 关于HTML5语义内容的学习(部分)
- ASP.NET 如何动态修改 Header 属性如添加 Meta 标签 keywords description!
- 关于unity导出xcode的工程中unity的内容部分。备忘录
- sharepoint 2007 内容查询web部件 如何显示信息日期
- Pega How To系列之一:如何在页面上动态显示/隐藏内容 ----by Cheney Wang
- 关于jquery 的绑定事件on 如何绑定动态生成的dom元素
- 计算机网络上关于交换机的部分问答内容
- 关于对《Windows Mobile平台应用与开发》一书中部分内容的疑问
- 关于如何用js来控制iframe里面的内容
- 关于后台动态模板添加内容的总结 Builder使用
- 关于sql中如何动态加WHERE条件
- 如何动态改变对话框中Static Text的内容?
- 详情页组件中的内容变化时,价格如何实现动态变化
- 自定义标签之二—传统自定义标签与简单自定义标签关于控制部分内容是否输出
- 关于如何显示 html 格式的文本内容
- 文本框输入内容进行动态提示(jquery部分)
- ASP.NET 如何动态修改 Header 属性如添加 Meta 标签 keywords description!