用于搜索引擎优化的MVC和元标记

时间:2010-12-02 12:03:34

标签: c# asp.net-mvc seo

我正在研究mvc2。我想要使​​用Meta标签。我是meta标签和seo的新手。如何在我的页面上使用元标记?在mvc上使用元标记的最佳方法是什么?

3 个答案:

答案 0 :(得分:3)

从程序员/技术的角度来看:元标记只是标记。

元标记的内容应该是什么,以及如何生成它们是特定于应用程序的。

答案 1 :(得分:3)

如今,元标签在搜索引擎优化中的作用越来越小。

但是,关于MVC,您可以按以下方式设置母版页:

<head runat="server">
    <title>
        <asp:ContentPlaceHolder ID="TitleContent" runat="server" />
    </title>
    <asp:ContentPlaceHolder  
        ID="MetaPlaceHolder" runat="server">
        <meta name="keywords" content="<%= ViewData["keywords"] %>" />
        <meta name="description" content="<%= ViewData["description"] %>" />
    </asp:ContentPlaceHolder>
    // lots os stuff missed out!!
</head>
<body>// more suff missed etc</body>

然后从您的各个控制器操作传递ViewData,以填充“关键字”和“说明”部分。还有其他方法,但这个方法很容易启动和运行,而不会对现有代码库造成重大干扰。

用法 - 将以下内容添加到每个必需的控制器操作

public ActionResult Index()
{
    // data would obviously come from some datastore but hardcoded for now below
    ViewData["keywords"] = "speed, camera, action";
    ViewData["description"] = "crime dun wrong";
    // other stuff happening too
}

那就是说,你应该更重要的是看看:

  • keyword density
  • 出站/入站链接
  • img alt tags
  • 页面标题
  • H1 / H2内容
  • 长网址细分和适用性

因为这些日子在SEO中越来越重要。所有上述内容都应该可以在谷歌上轻松搜索。

答案 2 :(得分:0)

我认为Jim对占位符位稍微过分复杂 - 没有必要。就这样做:

在_Layout主题部分:

<meta name="description" content=@ViewData["Description"]/>

在控制器中:

ViewData["Description"] = "My site has all the goodies!!";

也无需将其包裹在条件中;它不会抛出错误。如果未在控制器中设置ViewData,则标记将为空:

<meta name="description"/>
相关问题