Question

I have combed through the documentation but I could not find what I am looking for. It is possible what I am looking for is not possible, this is new territory to me.

I am using MVCSiteMapProvider for the first time. I need to make sure that search engines can crawl a list of dynamically created pages in my asp.net mvc site.

The view is created based off of two parameter: title and id. The url is spits out is defined in a custom route like this:

routes.MapRoute(
      "JobResults",                                           // Route name
      "JobSearch/{title}-{id}",                            // URL with parameters
        new { controller = "JobSearch", action = "Job" },  // Parameter defaults
        new[] { "MyApp.Web.Controllers" }
        );

So when I click on a link it will take me to: localhost:43736/JobSearch/chief-talent-officer-1710

I set up the sitemap plugin and messed with the .sitemap file so it looks like this:

<?xml version="1.0" encoding="utf-8" ?>
    <mvcSiteMap xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-4.0"
        xsi:schemaLocation="http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-4.0 MvcSiteMapSchema.xsd">

      <mvcSiteMapNode title="Home" controller="Home" action="Index" changeFrequency="Always" updatePriority="Normal">
        <mvcSiteMapNode title="About" controller="Home" action="About"/>
        <mvcSiteMapNode title="HiringSolutions" controller="Home" action="HiringSolutions"/>
        <mvcSiteMapNode title="Privacy Policy" controller="Home" action="Privacy"/>
        <mvcSiteMapNode title="Terms" controller="Home" action="Terms" />
        <mvcSiteMapNode title="Search" controller="JobSearch" action="Index"  changeFrequency="Always" updatePriority="Normal">
          <mvcSiteMapNode title="Job" controller="JobSearch" action="Job" changeFrequency="Always" updatePriority="High" route="JobResults"/>
        </mvcSiteMapNode>
      </mvcSiteMapNode>
</mvcSiteMap>

To see what it comes up with I called this on my index page: @Html.MvcSiteMap().Menu(false, true, true). It renders out this:

  • Home
  • About
  • HiringSolutions
  • Privacy Policy
  • Terms
  • Search
    • Job

How can I get it to do this dynamically?:

  • Home
  • About
  • HiringSolutions
  • Privacy Policy
  • Terms
  • Search
    • Job
      • /JobSearch/chief-talent-officer-1710
      • /JobSearch/another-one-1234
      • /JobSearch/another-one-1235
      • /JobSearch/another-one-1236
      • /JobSearch/another-one-1237

And once I have that (if possible), does this create a sitemap.xml file in the root of my site, or do I need to do something to make that reachable by bots?

Was it helpful?

Solution

Does the DynamicNodeProvider sound like what you're looking for? The sample code shows how to build a set of nodes from a database query.

public class StoreDetailsDynamicNodeProvider 
    : DynamicNodeProviderBase 
{ 
    public override IEnumerable<DynamicNode> GetDynamicNodeCollection(ISiteMapNode node) 
    {
        using (var storeDB = new MusicStoreEntities())
        {
            // Create a node for each album 
            foreach (var album in storeDB.Albums.Include("Genre")) 
            { 
                DynamicNode dynamicNode = new DynamicNode(); 
                dynamicNode.Title = album.Title; 
                dynamicNode.ParentKey = "Genre_" + album.Genre.Name; 
                dynamicNode.RouteValues.Add("id", album.AlbumId);

                yield return dynamicNode;
            }
        }
    } 
}

OTHER TIPS

Sounds like you need to create a manual page which lists all Jobs in your database, since the sitemap-provider (or Google) can't possibly know what to put as arguments to the Job- or Search-page.

Either that or create a script which generates the sitemap.xml for you. In either case this is a job you have to do, because only you know the structure of your data.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top