User297557456 posted
Hi,
You may add this class in your application and Inherit all your pages from this Class,
You may set your MetaKeyWords and MetaDescription like this:
this.MetaKeywords = "Blah...Blah...Blah...Blah...Blah...Blah...Blah..." ;
this.MetaDescription = "Blah...Blah...Blah...Blah...Blah...Blah...Blah..." ;
here is the class:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public class ExtendedPage : Page
{
#region "Do Not Edit"
HtmlMeta _MetaDesc;
HtmlMeta _MetaKeys;
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
this.Page.LoadComplete += new EventHandler(Page_LoadComplete);
}
#endregion
public string MetaKeywords
{
get
{
return ViewState["MetaKeywords"].ToString();
}
set
{
ViewState["MetaKeywords"] = value;
GenerateMetaKeywords();
}
}
public string MetaDescription
{
get
{
return ViewState["MetaDescription"].ToString();
}
set
{
ViewState["MetaDescription"] = value;
GenerateMetaDesc();
}
}
protected void Page_LoadComplete(object sender, EventArgs e)
{
Page page = sender as Page;
if (page == null) return;
if (this._MetaDesc != null) page.Header.Controls.Add(this._MetaDesc);
if (this._MetaKeys != null) page.Header.Controls.Add(this._MetaKeys);
}
protected void GenerateMetaDesc()
{
string content = this.ParseContent(this.MetaDescription);
if (string.IsNullOrEmpty(content)) return;
this._MetaDesc = new HtmlMeta();
this._MetaDesc.Name = "description";
this._MetaDesc.Content = content;
}
protected void GenerateMetaKeywords()
{
string content = this.ParseContent(this.MetaKeywords);
if (string.IsNullOrEmpty(content)) return;
this._MetaKeys = new HtmlMeta();
this._MetaKeys.Name = "keywords";
this._MetaKeys.Content = content;
}
private string ParseContent(string Content)
{
if (Content == null || Content.Length == 0) return string.Empty;
return Content.Trim();
}
}
let me know in case you need any other info. on the same.