''获取或设置页的meta关键字
Public Property Meta_Keywords()Property Meta_Keywords() As String
Get
Return _keywords
End Get
set
'' 删掉多余的空格
'' 译者注:\s匹配任何空白字符,包括空格、制表符、换页符等等。等价于 [\f\n\r\t\v]。
_keywords = Regex.Replace(value, "\\s+", " ")
End Set
End Property
'' 获取或设置页的meta描述
Public Property Meta_Description()Property Meta_Description() As String
Get
Return _description
End Get
Set(ByVal value As String)
'' 删掉多余的空格
'' 译者注:\s匹配任何空白字符,包括空格、制表符、换页符等等。等价于 [\f\n\r\t\v]。
_description = Regex.Replace(value, "\\s+", " ")
End Set
End Property
End Class
Meta_Keywords属性和Meta_Description属性是公共的,你可以在类实例化后设置它们。当某个类继承自这个类并被初始化后,Base_Init将被调用并在页中增加meta标签
C#
public partial class home : BasePage
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
VB
Partial Class homeClass home
Inherits BasePage
Sub Page_Load()Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
End Sub
End Class
注意每一个继承自BasePage的页都可以通过属性或代码来插入meta标签。现在我们可以直接在.aspx文件的@Page指令中指定Meta_Keywords属性和Meta_Description属性的值。示例如下
<%@ Page Language="C#" MasterPageFile="~/PageTags.master" AutoEventWireup="true" CodeFile="home.aspx.cs" Inherits="home"
CodeFileBaseClass="BasePage"
Title="My home page title"
Meta_Keywords="page directive, extension, do.Net, asp.Net"
Meta_Description="This is the meta description for my home pag