简体   繁体   English

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

[英]MVC and Meta Tags for Search Engine Optimization

I am working on mvc2. 我正在制作mvc2。 I want used Meta tags. 我想要使​​用元标记。 I am new on the meta tags and seo. 我对meta标签和seo还是陌生的。 How can used meta tags on my page? 如何在我的页面上使用元标记? What is the best way to used meta tags on mvc? 在MVC上使用元标记的最佳方法是什么?

From a programmer/technology point of view: meta tags are just tags. 从程序员/技术的角度来看:元标记只是标记。

What the content of your meta tags should be, and how to generate them, is application specific. 您的元标记内容应该是什么,以及如何生成它们,取决于应用程序。

Meta tags play an ever decreasing role in SEO these days. 这些天来,元标记在SEO中的作用越来越小。

However, in relation to MVC, you can set your masterpage up along the following lines: 但是,相对于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>

and then pass the ViewData from your individual controller actions to populate the 'keywords' and 'description' sections. 然后从您的各个控制器操作中传递ViewData来填充“关键字”和“说明”部分。 There are other ways, but this one is fairly simple to get up and running without major disruption to your existing codebase. 还有其他方法,但是这种方法很容易启动和运行,而不会严重破坏现有代码库。

usage - add the following to each required controller action 用法-将以下内容添加到每个必需的控制器操作中

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
}

That said, you should more importantly be looking at: 也就是说,您应该更重要地关注以下方面:

  • keyword density 关键字密度
  • outbound/inbound links 出站/入站链接
  • img alt tags img alt标签
  • page titles 页面标题
  • H1/H2 contents H1 / H2含量
  • long URL segmentation and applicability 较长的网址细分和适用性

as these play an ever increasing importance in SEO these days. 因为这些在SEO中越来越重要。 all of the above should be easily searchable on google. 以上所有内容都可以在Google上轻松搜索。

I think Jim is over-complicating it just a bit with the placeholder bit - it's not necessary. 我认为Jim只是用占位符使它过于复杂了-没必要。 Just do this: 只要这样做:

In _Layout head section: 在_Layout头部分中:

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

In the controller: 在控制器中:

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

Also no need to wrap it in a conditional; 也无需将其包装成条件包装; it won't throw an error. 它不会抛出错误。 If you don't set ViewData in the controller the tag will just be empty: 如果您未在控制器中设置ViewData,则标记将为空:

<meta name="description"/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM