Method 1
If (! Ispostback)
{
// Page title
Page. Title = "my website title"; // you must set the webpage head tag to the server control mode, that is,
// Description webpage description
Htmlmeta DESC = new htmlmeta ();
Desc. Name = "Description ";
Desc. content = "my website description ";
Page. header. Controls. Add (DESC );
// Keyword webpage keyword
Htmlmeta KEYWORDS = new htmlmeta ();
Keywords. Name = "keywords ";
Keywords. content = "my website keywords ";
Page. header. Controls. Add (keywords );
}
Method 2 <Non-master page>
To optimize the search engine during webpage development, adding the Title Keyword description of the page is one of the most common methods. Asp.net MethodCodeAs follows:
Public void seo_head (String title, string keyword, string description)
{
Page. Title = title + "-My blog -";
Htmlmeta metakeywords = new htmlmeta ();
Htmlmeta metadeworkflow = new htmlmeta ();
Metakeywords. Name = "keywords ";
Metakeywords. content = keyword;
Metadeworkflow. Name = "Description ";
Metadeworkflow. content = description;
Header1.controls. Add (metakeywords );
Header1.controls. Add (metadegion); // header1 is the ID of the head
}
--------- Delete the title tag of the content page if there is no master page ----------
III others
The recommended method is as follows:
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);
}