触摸屏租赁
Touch screen rental
广告机租赁
Advertising rental
机器人租赁
Robot leasing
 当前位置:首页 > > asp.net如何在后台加标题和关键字和描述

asp.net动态设置标题title 关键字keywords 描述descrtptions

方法一

if (!IsPostBack)
{
//Page title网页标题
Page.Title = “我的网站标题”;//须将网页head标签设成服务器控件模式,即<head runat="server">,否则无效

            //Description网页描述
HtmlMeta desc = new HtmlMeta();
desc.Name = "Description";
desc.Content = "我的网站描述";
Page.Header.Controls.Add(desc);

            //Keyword网页关键字
HtmlMeta keywords = new HtmlMeta();
keywords.Name = "keywords";
keywords.Content = “我的网站关键字";
Page.Header.Controls.Add(keywords);

}





方法二<非母版页面下>
在网页的开发中为了搜索引擎的优化,添加页面的title keyword description是最常用的方法之一。asp.net的方法代码如下所示:
public void SEO_HEAD(string title, string keyword, string description)
{
Page.Title = title + "-my blog-";
HtmlMeta metaKeyWords = new HtmlMeta();
HtmlMeta metaDescription = new HtmlMeta();
metaKeyWords.Name = "Keywords";
metaKeyWords.Content = keyword;
metaDescription.Name = "description";
metaDescription.Content = description;
Header1.Controls.Add(metaKeyWords);
Header1.Controls.Add(metaDescription);//Header1是head的id
}

---------如果没有母版页的话把内容页的title标签删除----------



三 其他

推荐的简单做法如下:

protected void Page_Load(object sender, EventArgs e)
{
//Page title
Page.Title = "This is a title and meta test page.";

   //Encode/Content type
HtmlMeta encode = new HtmlMeta();
encode.HttpEquiv = "Content-Type";
encode.Content = "text/html; charset=utf-8";
Page.Header.Controls.Add(encode);

   //Language
HtmlMeta lang = new HtmlMeta();
lang.HttpEquiv = "Content-Language";
lang.Content = "zh-cn";
Page.Header.Controls.Add(lang);

   //Description
HtmlMeta desc = new HtmlMeta();
desc.Name = "Description";
desc.Content = "Test the meta controls";
Page.Header.Controls.Add(desc);

   //Keyword
HtmlMeta keywords = new HtmlMeta();
keywords.Name = "keywords";
keywords.Content = "title,meta,test,page";
Page.Header.Controls.Add(keywords);

   //Link/CSS
HtmlLink cssLink = new HtmlLink();
cssLink.Href = "MasterPage.css";
cssLink.Attributes.Add("rel", "stylesheet");
cssLink.Attributes.Add("type", "text/css");
Page.Header.Controls.Add(cssLink);
}


工作室地址:重庆石桥铺电脑城B座 | 微信:z35544216 | 网址:www.35544216.com