MVC and Meta Tags for Search Engine Optimization

扶醉桌前 提交于 2019-12-08 05:13:02

问题


I am working on mvc2. I want used Meta tags. I am new on the meta tags and seo. How can used meta tags on my page? What is the best way to used meta tags on mvc?


回答1:


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.

  • Google's article on meta tags
  • W3schools has a nice simple article



回答2:


Meta tags play an ever decreasing role in SEO these days.

However, in relation to MVC, you can set your masterpage up along the following lines:

<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. 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
  • page titles
  • H1/H2 contents
  • long URL segmentation and applicability

as these play an ever increasing importance in SEO these days. all of the above should be easily searchable on google.




回答3:


I think Jim is over-complicating it just a bit with the placeholder bit - it's not necessary. Just do this:

In _Layout head section:

<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:

<meta name="description"/>


来源:https://stackoverflow.com/questions/4334769/mvc-and-meta-tags-for-search-engine-optimization

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!