Adding Keyword And Description meta tags to each page by inheritence
2009-02-09 01:14
429 查看
如何加Keyword 和 Description meta tags 到每个页面,看代码:
//Change the line
// public partial class SomePage : System.Web.UI.Page
//to
// public partial class SomePage : PageEx
public partial class SomePage : PageEx
{
protected void Page_Load(object sender, EventArgs e)
{
Title = "Free Piston Power Pack (FP3)";
this.Description = "Your Description of the page";
this.Keywords = new string[] { "keyword1", "keyword1" ,"keyword1"};
}
}
//add the PageEx.cs in the App_Code Directory
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;
/// <summary>
/// Summary description for PageExPage
/// </summary>
public class PageEx : System.Web.UI.Page
{
private HtmlMeta metaDescription = new HtmlMeta();
private HtmlMeta metaKeywords = new HtmlMeta();
public string Description
{
get { return metaDescription.Content; }
set { metaDescription.Content = value; }
}
public string[] Keywords
{
get
{
if (metaKeywords.Content == null)
{
return new string[] { "" };
}
else
{
return metaKeywords.Content.Split(new char[] { ',' });
}
}
set
{
if (value != null)
{
metaKeywords.Content = string.Join(",", value);
}
}
}
public PageEx()
{
Init += new EventHandler(PageEx_Init);
}
void PageEx_Init(object sender, EventArgs e)
{
//Add the description Meta control
metaDescription.Name = "description";
Page.Header.Controls.Add(metaDescription);
//Add the keywords Meta control
metaKeywords.Name = "keywords";
Page.Header.Controls.Add(metaKeywords);
}
}
文章出处:http://msdn.microsoft.com/en-us/library/wtxbf3hh.aspx 【直接拉到最后】
//Change the line
// public partial class SomePage : System.Web.UI.Page
//to
// public partial class SomePage : PageEx
public partial class SomePage : PageEx
{
protected void Page_Load(object sender, EventArgs e)
{
Title = "Free Piston Power Pack (FP3)";
this.Description = "Your Description of the page";
this.Keywords = new string[] { "keyword1", "keyword1" ,"keyword1"};
}
}
//add the PageEx.cs in the App_Code Directory
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;
/// <summary>
/// Summary description for PageExPage
/// </summary>
public class PageEx : System.Web.UI.Page
{
private HtmlMeta metaDescription = new HtmlMeta();
private HtmlMeta metaKeywords = new HtmlMeta();
public string Description
{
get { return metaDescription.Content; }
set { metaDescription.Content = value; }
}
public string[] Keywords
{
get
{
if (metaKeywords.Content == null)
{
return new string[] { "" };
}
else
{
return metaKeywords.Content.Split(new char[] { ',' });
}
}
set
{
if (value != null)
{
metaKeywords.Content = string.Join(",", value);
}
}
}
public PageEx()
{
Init += new EventHandler(PageEx_Init);
}
void PageEx_Init(object sender, EventArgs e)
{
//Add the description Meta control
metaDescription.Name = "description";
Page.Header.Controls.Add(metaDescription);
//Add the keywords Meta control
metaKeywords.Name = "keywords";
Page.Header.Controls.Add(metaKeywords);
}
}
文章出处:http://msdn.microsoft.com/en-us/library/wtxbf3hh.aspx 【直接拉到最后】
相关文章推荐
- How to query_posts using meta_query to orderby meta_key AND have a secondary sort by date?
- how to loop through the Params property for a page and how to display each key/value pair
- Using SiteMap and MasterPages to set META Tags in ASP.NET and C#
- SEO in ASP.NET 4 Websites - Page.MetaKeywords and Page.MetaDescription
- Write a program to copy its input to its output, replacing each tab by \t, each backspace by \b, and each backslash by \\. This makes tabs and backspa
- Git: Adding and Removing Tags on GitHub
- asp.net配置报错 “An error was encountered. Please return to the previous page and try again. ”
- Adding headers and footers to RecyclerView.
- How to Change the DBID and the DBNAME by using NID [ID 224266.1]
- How to Change the DBID and the DBNAME by using NID
- Check your site and build meta tags for search engines
- How to create and delete a SharePoint site by web application
- A step-by-step guide to the use of the Intel OpenCV library and the Microsoft DirectShow technology
- Sys.WebForms.PageRequestManagerParserErrorException - what it is and how to avoid it
- Linux command to display package description, information, version and usage
- Connect to URL and dump webpage in Groovy - Stack Overflow
- Sys.WebForms.PageRequestManagerParserErrorException - what it is and how to avoid it
- Mac OS X - A step-by-step guide to installing Go and building your first web service
- Moving git repository and all its branches, tags to a new remote repository keeping commits history
- How to SUM and GROUP BY of JSON data?