The basis of using Mvcsitemapprovider to implement Sitemap in MVC

Source: Internet
Author: User

Mvcsitemapprovider is a menu, site map, site map path feature, and more tools for ASP. It provides the ability to configure the use of an pluggable architecture, which can be XML, a database, or dynamically generate a navigation structure.

There are three ways to implement the Sitemap in Mvcsitemapprovider: Xml,.net attributes,idynamicnodeprovider.

Below, we first implement the site map by XML.

1. Create a new MVC4 project and select an Internet application. The Mvcsitemapprovider is then installed through NuGet, and in this case Mvc4 is used, so mvcsitemapprovider Mvc4 needs to be downloaded. After the installation is successful, the Mvc.sitemap file appears.

2. The way XML is used requires configuration in the Mvc.sitemap file. The default configuration is as follows:

1 <?xml version= "1.0" encoding= "Utf-8"?> 2 <mvcsitemap xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance "3             xmlns=" http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-4.0 "4             xsi:schemalocation="/http/ mvcsitemap.codeplex.com/schemas/mvcsitemap-file-4.0 mvcsitemapschema.xsd "> 5  6   <mvcsitemapnode Title= "Home" controller= "Home" action= "Index" > 7     <mvcsitemapnode title= "about" controller= "Home" action= " About "/> 8   </mvcSiteMapNode> 9 </mvcSiteMap>

3. In the _layout.cshtml of the shared folder under the Views folder, we will place the header under <nav> under the UL comment, and then use @html.mvcsitemap (). Menu () to generate menus.

Then add @Html. Mvcsitemap () above the @renderbody (). SiteMapPath () is used to generate so-called bread crumbs.

The modified _layout.cshtml content is as follows:

4. So far, we have completed the most basic configuration, the following we look at the effect. Open the Web site and you can see the resulting menu. Click on about to see the generated breadcrumbs.

In this chapter we briefly explain the use of Mvcsitemapprovider XML to generate a sitemap, and the next one we'll delve into XML to generate the site map.

Novice Don't Spray ~

Source: >

Related Article

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.