Use the razor engine to do an SEO Helper

Source: Internet
Author: User

The items at hand need to be SEO optimized, just consider doing an SEO Helper, using the asp.net MVC Razor view engine, which is really easy and enjoyable:

1, first of all, in the Layout page render a section, called SEO, as follows:

<head> <title> @ViewBag .title</title> @RenderSection ("SEO", false) ...

2. Add a seo.cshtml to the App_Code code as follows:

@helper metatag (String description,string keywords) {<meta name= "description" content= "@description"/> Name= "KEYWORDS" content= "@keywords"/>} @helper NoIndex () {<meta name= "robots" content= "NoIndex"/>}

3, in the implementation page, the definition of SEO section

@section SEO {@SEO. MetaTag ("This is a description to my site.", "This keyword,serperated by Comma,another,keyword")}

When you browse the page, you can find <meta name= "description" content= ... "/> and <meta name=" keyword "content=" ... "> has been added to the page.

Of course, if you do not want the search engine included in the page, you can already use the @SEO. NoIndex () written as a not allowed to be included in the <meta>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

Tags Index: