SEO for ASP.NET网站:内容

这是一系列文章中的第一个,探索如何优化搜索引擎的ASP.NET网站。该系列中的每篇文章都集中在特定主题上,并查看ASP.NET开发人员可用的功能和工具,以帮助使网站搜索引擎友好,从而从搜索结果中改进排名和点击次数。第一篇文章将研究如何以最佳方式向搜索引擎呈现您的网站内容。

全系列文章包括

质量内容

如果您希望您的网站长期排名,高质量原始内容的重要性不能夸大。如果您的内容为目标受众提供价值,他们将想通过社交媒体和其他途径链接到它并分享。您获得的更好的质量链接,您将在排名越好。对此没有真正的快捷方式,但有一些技术方式可以展示您的内容,以便更加搜索引擎友好。但是,我不能在为您的网站创建内容时,在您的网站上创建内容时,它无法重大压力。

标题和metatags.

Every page should have a title. This is set in the <title> element within the <head> section of the page. The title is displayed in search engines result pages (SERPs). The title should be unique, descriptive and accurate. The title should contain keywords that reflect the page content, and it should be easy to read. There are no hard and fast rules in terms of length, but you will often see recommendations to keep the character count below 60. This is mainly to accommodate what is displayed in SERPs, but any additional characters are processed as part of the ranking system.

设置标题 - Web表单和MVC

If you are developing with Web Forms, there are a number of ways to set the page title. You could hard code it in the Master page's HTML, but doing that will result in every page in your site having the same title. If you want a unique and descriptive title per page, you will set the title at the page level. If the title is static, you can set it in the aspx file in the @ Page directive:

<%@ Page Title="About my site" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="About.aspx.cs" Inherits="WebFormsSEO.About" %>

If you want to set a dynamic title, for example you might want to use the title of your blog article or recipe depending on your site content, you can do this from code-behind by setting the Page.Title (or this.Title 或者 just Title) value. The approach you take to setting the value depends on the source of the data being used to construct your title. Most often, you will use a control's DataBound 或者 RowDataBound event handler to access the control's data source and extract whatever values you want. Whichever way you choose, you should be aware of the order of precedence that governs what value eventually appears.

无论您将始终出现母版页面的HTML中的硬代码。标准Web表单站点模板通过硬编码使用此功能" - 我的ASP.NET应用程序" as part of the <title> value, but it also allows the first part of the <title> to be set dynamically:

<title><%: Page.Title %> - 我的ASP.NET应用程序</title>

When you add a new aspx file to your application, the default value for Title in the @ Page directive is an empty string:

<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master"

If you leave it like that, no matter where else you try to set the Page.Title value, it will stay as an empty string. So unless you want to hard code a value in the @ Page directive, you should delete the Title entry from it. Assuming you don't leave this value as an empty string, anything you set in the @ Page directive will be overwritten by whatever you set in the page's code-behind. And this in turn will be overwritten by anything that you set from the Master Page's code-behind.

The MVC template also includes some default mark up to cater for the value of the <title> element in the layout page:

<title>@ViewBag.Title - 我的ASP.NET应用程序</title>

You can manage the value of ViewBag.Title by setting it in the controller. You can also set it in the content page:

@{
    ViewBag.Title = "Home Page";
}

This will override any value set in the controller. Note, since ViewBag is a dynamic object, instead of using Title as the property name, you can just as easily use PageTitle, or indeed anything you like.

元描述

Meta descriptions are your opportunity to advertise your page on SERPs. They are set using the HTML <meta> tag:

<meta name="description" content="This is where the description goes" />

这应该用于提供页面内容的描述。它应该包括与内容相关的关键词,并以自然语言编写..不是关键字的列表。 Meta描述可以由SERP中的大多数搜索引擎使用,以便搜索者知道每个结果是什么。

在SERPS中使用META描述

上面的图像说明了谷歌如何在搜索结果中使用Meta描述(以黄色突出显示)"发送电子邮件ASPNET MVC"。谷歌将不会始终使用元描述,如果总长度超过160个字符,则当然不会使用所有内容。如果感觉比Meta描述的内容更合适,Google提供的文本将从页面内容本身取出。在这一特殊情况下,我的描述超出了160个限制,通过他们决定在描述开始时包括包括文章日期的决定进一步限制。

在引入ASP.NET 4之前,您将使用a 内容PlaceHolder和HTMLMeta类 to set a meta description in a Web Forms site. Since ASP.NET 4, the Page class has included a MetaDescription property which enables Web Forms developers to set this value easily form code-behind:

public partial class About : Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        MetaDescription = "A page that describes what we are about";
    }
}

MVC developers can use a similar approach to setting the title, by using a placeholder in the layout page and ViewBag to pass a description dynamically:

<meta name="description" content="@ViewBag.Description">

在我的情况下,我在数据库中有一个字段,用于每篇文章的介绍段落,另一个用于元描述。如果我没有填充描述字段,则第一段用作元描述的内容:

ViewBag.Description = article.Description != null ? article.Description : article.Introduction;

Meta关键词

It's generally recognised these days that meta keywords serve no useful purpose at all. Search engines by and large completely ignore them. Nevertheless, some developers still like to include them, and ASP.NET 4 introduced a MetaKeywords property for the Page class along with the MetaDescription property:

protected void Page_Load(object sender, EventArgs e)
{
    MetaKeywords = "spam, spam, spam";
}

结构化数据/丰富的片段

谷歌有时会尝试从搜索结果中提取一些元数据,以增强SERPS列表中的条目。上一个图像显示作为描述的一部分包含的文章日期。其他搜索结果可以包括谷歌的形式的更多结构化数据,作为“丰富的片段”作为显示结果的下一个图像"圣诞蛋糕食谱"说明(突出显示是我的):

丰富的片段

除了描述之外,结果还显示了准备和烹饪蛋糕所需的图像,额定值,总时间,以及在第一个结果的情况下,配方的卡路里值。我相信谷歌工程师聪明的聪明能够使用自然语言处理(或他们工作的任何alpha-geek字段)来解析来自网页的这些数据,但是通过使用结构化数据,他们的工作是更容易的网页作者。拥有您的列表增强,可能会导致更高的点击率。

谷歌和其他搜索引擎识别的结构化数据词汇表在 Schema.org.。一种 各种各样的实体都是迎合 包括技术文章,音乐事件,医疗程序,儿童保育业务等事情,这些词汇表以两种方式之一应用于网页:作为HTML元素的特殊属性;或者 json-ld.。如果您选择使用属性,可以使用两个替代编码之一来应用它们, microdata. 或者 RDFA.。我在我的网站上使用microdata,以便在看看JSON-LD之前我将探索的格式。

microdata.

Typically, an identifiable section of a page will be devoted to the item you want to mark up. It might be the whole page, or just some part of it. You use the itemscope attribute to define the area that encloses the information relating to the item, and itemtype to specify the actual type of item you are describing. The value of the itemtype attribute is a URL pointing to the schema for the specific item. A technical article might be enclosed in a div 或者 an HTML5 article tag.

<article itemscope itemtype="http://schema.org/TechArticle">

Thereafter, you use attributes to describe the item-specific properties according to the itemtype under focus. In the case of a 技术文章, these item might include articleBody, author, genre and so on. Google specifies required properties for certain items for the markup to be valid. 在文章的情况下, Google requires a headline, datepublished and image. Individual properties are marked up using the itemprop attribute:

<h1 itemprop="headline">
    @Model.Article.Headline
</h1>

您可以通过元标记提供用户对用户不可见的其他信息。例如,您可以为用户提供速率内容的设施,并且评级本身由一个表示 emplegaterating. 物品。您可以告诉搜索引擎和其他解析器,评分系统的最高和最低可能值如下:

<meta itemprop="bestRating" content="5" />
<meta itemprop="worstRating" content="1" />

json-ld.

json-ld.(链接数据的JavaScript对象表示法)在脚本标记或单独的.js文件中声明。与Mocrodata属性不同,它允许开发人员在一个地方提供关于它们的内容的元数据,而不是与内容本身混合。这是一个具有评级的典型文章可能会出现在剃刀视图中:

<script type="application/ld+json">
    "@@context": "http://schema.org",
    "@@type": "TechArticle",
    "headline": "@Model.Article.Headline",
    "image": [
    "image1.jpg"
    ],
    "datePublished": "@Model.Article.DateCreated.ToString("T"),
    "description": "@Model.Article.Description",
    "articleBody": "@Model.Article.Maintext",
    "aggregateRating": {
        "@@type": "AggregateRating",
        "ratingValue": "@Model.ArticleRating.AverageRating",
        "reviewCount": "@Model.ArticleRating.TotalRaters"
    }
</script>

The context and type properties are prefixed with single literal @ signs, but in the Razor view, this has to be escaped which is why they are doubled. You only need one @ sign in a Web Forms aspx file:

<script type="application/ld+json">
    "@context": "http://schema.org",
    "@type": "TechArticle",
    "headline": "<%: Model.Article.Headline %>"
    ...

 

概括

本文查看了一些方法,您可以在其中展示您的ASP.NET网站的内容,以提高其对搜索引擎的可见性和意义,并可能增加您的点击率。它涵盖了标准HTML标题和元描述标签的重要性以及如何使用它们。然后,该文章通过使用结构化数据探索了如何获得搜索列表,并显示两种方法可以使用结构化数据。

该系列中的下一篇文章将审查搜索引擎在URL上的重要性以及如何为最佳SEO结果进行优化。