Dynamically set various meta of webpages
Today's website optimization is overwhelming, and meta optimization is an essential step. Each page must have related meta information, and each page must be added. However, the meta information on each page cannot be the same, which makes the search engine more friendly. Therefore, each page must dynamically generate various meta information.
There are two methods to achieve the requirements:
(1) add an ID and ruanat for the Meta to be added as the server control and use <meta name = "Description" content = "description of this website" id = "Description" runat = "server" />
In the background, write description. content = "Description of the Website ";
(2) dynamically generate a Meta control
Write data directly in the background. Code As follows:
Htmlhead head = (htmlhead) page. header;
Htmlmeta contenttype = new htmlmeta (); // sets the character set used on the page.
Contenttype. httpequiv = "Content-Type ";
Contenttype. content = "text/html; charset = gb2312 ";
Head. Controls. Add (contenttype );
In this way, you can. The following is my code for each mate, and each page must be fully written. Just write the code that is conducive to optimization.
Page code:
<% @ Page Language = "C #" autoeventwireup = "true" codefile = "default. aspx. cs" inherits = "metatest_default" %>
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<% -- <Meta name = "Description" content = "Description" id = "Description" runat = "server"/>
<Meta name = "keywords" content = "keywords" id = "keywords" runat = "server"/> -- %>
<Title> </title>
</Head>
<Body>
<Form ID = "form1" runat = "server">
<Div>
</Div>
</Form>
</Body>
</Html>
Background code:
// Description. content = "description of this website ";
// Keywords. content = "website construction, website optimization ";
Page. Title = "various meta writing methods ";
Htmlhead head = (htmlhead) page. header;
Htmlmeta contenttype = new htmlmeta (); // sets the character set used on the page.
Contenttype. httpequiv = "Content-Type ";
Contenttype. content = "text/html; charset = gb2312 ";
Head. Controls. Add (contenttype );
Htmlmeta description = new htmlmeta (); // description is used to tell the search engine the main content of your website.
Description. Name = "Description ";
Description. content = "describes the main functions and functions of the Website ";
Head. Controls. Add (description );
Htmlmeta KEYWORDS = new htmlmeta (); // keywords is used to tell the search engine what the keywords on your webpage are.
Keywords. Name = "keywords ";
Keywords. content = "Enter the website keywords here. Note that each keyword is separated by a comma ";
Head. Controls. Add (keywords );
Htmlmeta author = new htmlmeta (); // author of The webpage
Author. Name = "author ";
Author. content = "bangs, 446557021@qq.com ";
Head. Controls. Add (author );
Htmlmeta robots = new htmlmeta (); // The robot wizard sets robots to tell robots which pages need to be indexed and which pages do not need to be indexed. Content parameters include all, none, index, noindex, follow, and nofollow. The default value is all.
Robots. Name = "Robots ";
Robots. content = "NONE ";
Head. Controls. Add (robots );
Htmlmeta expires = new htmlmeta (); // set the expiration time of the webpage.
Expires. httpequiv = "expires ";
Expires. content = "Fri, 12 Jan 2001 18:18:18 GMT ";
Head. Controls. Add (expires );
Htmlmeta Pragma = new htmlmeta (); // disable the browser from accessing the page content from the cache of the Local Computer
Pragma. httpequiv = "Pragma ";
Pragma. content = "no-Cache ";
Head. Controls. Add (Pragma );
Htmlmeta setcookie = new htmlmeta (); // If the webpage expires, the cookie on the disk will be deleted. The GMT time format must be used.
Setcookie. httpequiv = "Set-cookie ";
Setcookie. content = "cookievalue = xxx; expires = Friday, 12-Jan-2001 18:18:18 GMT; Path = /";
Head. Controls. Add (setcookie );
htmlmeta windowtarget = new htmlmeta (); // display window settings force the page to be displayed on an independent page in the current window to prevent others from calling their own page in the framework
windowtarget. httpequiv = "window-target";
windowtarget. content = "_ top";
head. controls. add (windowtarget);