I’m working on an MVC3 web application using the razor view engine. I’m looking for a solution to generate meta keywords and description automatically on my pages.
I’ve already found this solution here on stackoverflow, the idea is looking good. But since I’m planning to post blogs etc… on my website I want the meta keywords and description to be auto generated based on the content of the page.
Soo far I’ve got the following things in mind. Let’s say that the current HTML looks like below;
<html>
<head>
</head>
<body>
<header></header>
<div id="container">
<div id="sideBar"></div>
<div id="pageHeader"></div>
<div id="content">
<!--This part contains the dynamic content-->
</div>
<div class="clear"></div>
</div>
<footer></footer>
</body>
</html>
The desired situation for me would be something like below;
<html>
<head>
@Html.MetaKeywords()
@Html.MetaDescription()
</head>
<body>
<header></header>
<div id="container">
<div id="sideBar"></div>
<div id="pageHeader"></div>
<div id="content">
<!--This part contains the dynamic content-->
</div>
<div class="clear"></div>
</div>
<footer></footer>
</body>
</html>
Said all this I’ve got the following questions left unanswered, hope someone can help.
- The situation described above, with the HTML-helpers. Is this an good and logic approach to generate keywords and description on every single page, based on the content?
- If this is, does anyone has experience and maybe an good example?
- If not, are there any other good options? Other then using an attribute on each controller action? This still is an option, but it doesn’t generate keywords an description based on my page content.
I hope someone can help me out. Thanks!
If I’m understanding correctly, you want to be able to auto generate the metadata based on the text inside the content div?
I would try passing that text / html / model into the MetaKeywords and MetaDescription functions, and allowing them to parse / analyze / look-up the information you need to put in the metadata.