What's the problem with this sitemap?

Sep 2, 2010 at 9:50 PM

<?xml version="1.0" encoding="utf-8" ?>
<mvcSiteMap xmlns="http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-2.0" enableLocalization="true">
  <!-- Home -->
  <mvcSiteMapNode title="Home" controller="Home" action="Index" changeFrequency="Always" updatePriority="Normal" key="home">

    <!-- Menu de Cadastros -->
    <mvcSiteMapNode title="Cadastros" key="cadastros">

      <!-- Unidade de Negocio -->
      <mvcSiteMapNode title="Unidade de Negocio" controller="UnidadeNegocio" action="Index" key="unidade" >
        <mvcSiteMapNode title="Criar" controller="UnidadeNegocio" action="CreateUnidadeNegocio" key="createunidade" />
        <mvcSiteMapNode title="Editar" controller="UnidadeNegocio" action="EditUnidadeNegocio" key="editunidade" />
        <mvcSiteMapNode title="Detalhes" controller="UnidadeNegocio" action="DetailsUnidadeNegocio" key="detalhesunidade" />
      </mvcSiteMapNode>

      <!-- Usuario -->
      <mvcSiteMapNode title="Usuario" controller="Usuario" action="Index" key="usuario" >
        <mvcSiteMapNode title="Criar" controller="Usuario" action="CreateUsuario" key="createusuario" />
        <mvcSiteMapNode title="Editar" controller="Usuario" action="EditUsuario" key="editusuario" />
        <mvcSiteMapNode title="Detalhes" controller="Usuario" action="DetailsUsuario" key="detalhesusuario" />
      </mvcSiteMapNode>

      <!-- Noticia -->
      <mvcSiteMapNode title="Noticia" controller="Noticia" action="Index" key="noticia" >
        <mvcSiteMapNode title="Criar" controller="Noticia" action="CreateNoticia" />
        <mvcSiteMapNode title="Editar" controller="Noticia" action="EditNoticia" />
        <mvcSiteMapNode title="Detalhes" controller="Noticia" action="DetailsNoticia" />
      </mvcSiteMapNode>

      <!-- Evento -->
      <mvcSiteMapNode title="Evento" controller="Evento" action="Index" >
        <mvcSiteMapNode title="Criar" controller="Evento" action="CreateEvento" />
        <mvcSiteMapNode title="Editar" controller="Evento" action="EditEvento" />
        <mvcSiteMapNode title="Detalhes" controller="Evento" action="DetailsEvento" />
      </mvcSiteMapNode>

    </mvcSiteMapNode>

    <!-- Imovel -->
    <mvcSiteMapNode title="Imoveis" controller="Imovel" action="Index" changeFrequency="Always" updatePriority="Normal" key="imoveis" >
      <mvcSiteMapNode title="Inserir imovel" Action="Create" Controller="Imovel" />
      <mvcSiteMapNode title="Editar" Action="Edit" dynamicProvider="TesteServices.SiteMap.DynamicImovelSiteMap, TesteServices" />
    </mvcSiteMapNode>

  </mvcSiteMapNode>
</mvcSiteMap>

Below the code of the dynamic node:

        imoveisEntities _entities = new imoveisEntities();

        public override IEnumerable<DynamicNode> GetDynamicNodeCollection()
        {
            var returnValue = new List<DynamicNode>();

            foreach (var item in _entities.IMOVELSet)
            {
                DynamicNode node = new DynamicNode();
                node.Title = string.Format("{0} - {1:0000}", item.TIPOCOMERCIO, item.CODIGO);
                node.ParentKey = "imoveis";
                node.Key = string.Format("imolvel_{0}", item.CODIGO);
                node.RouteValues.Add("IDIMOVEL", item.IDIMOVEL);

                returnValue.Add(node);
            }

            return returnValue;
        }
The problem is "An item with the same key has already been added."

 

 

Coordinator
Sep 9, 2010 at 6:50 PM

Can you post a stacktrace of that error?

Sep 9, 2010 at 8:08 PM

I simplified the sitemap, it works for a while then...

Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.

Stack Trace:

[ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.]
   System.Reflection.RuntimeModule.GetTypes(RuntimeModule module) +0
   System.Reflection.RuntimeModule.GetTypes() +4
   System.Reflection.Assembly.GetTypes() +78
   MvcSiteMapProvider.<>c__DisplayClass18.<GetControllerTypeWithinNamespaces>b__c(Assembly a) +31
   System.Linq.WhereSelectArrayIterator`2.MoveNext() +4184288
   System.Linq.<SelectManyIterator>d__31`3.MoveNext() +376
   MvcSiteMapProvider.DefaultControllerTypeResolver.GetControllerTypeWithinNamespaces(String area, String controller, HashSet`1 namespaces) +1068
   MvcSiteMapProvider.DefaultControllerTypeResolver.ResolveControllerType(String areaName, String controllerName) +245
   MvcSiteMapProvider.AuthorizeAttributeAclModule.IsAccessibleToUser(IControllerTypeResolver controllerTypeResolver, DefaultSiteMapProvider provider, HttpContext context, SiteMapNode node) +127
   MvcSiteMapProvider.DefaultAclModule.IsAccessibleToUser(IControllerTypeResolver controllerTypeResolver, DefaultSiteMapProvider provider, HttpContext context, SiteMapNode node) +149
   MvcSiteMapProvider.DefaultSiteMapProvider.IsAccessibleToUser(HttpContext context, SiteMapNode node) +24
   System.Web.SiteMapNode.IsAccessibleToUser(HttpContext context) +17
   System.Web.StaticSiteMapProvider.GetChildNodes(SiteMapNode node) +378
   MvcSiteMapProvider.DefaultSiteMapProvider.FindControllerActionNode(SiteMapNode rootNode, IDictionary`2 values) +59
   MvcSiteMapProvider.DefaultSiteMapProvider.FindSiteMapNode(HttpContext context) +309
   System.Web.SiteMapProvider.get_CurrentNode() +56
   MvcSiteMapProvider.Web.Html.SiteMapPathHelper.SiteMapPath(MvcSiteMapHtmlHelper helper, String separator, String separatorCssClass, String linkCssClass, Boolean currentNodeAsLink, Object htmlAttributes) +80
   MvcSiteMapProvider.Web.Html.SiteMapPathHelper.SiteMapPath(MvcSiteMapHtmlHelper helper, String separator) +24
   ASP.views_masteradminexterno_master.__Render__control1(HtmlTextWriter __w, Control parameterContainer) in d:\Projetos\Solution Source\SAIT.root\SAIT\TesteServices\Views\MasterAdminExterno.Master:89
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +109
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +8
   System.Web.UI.Control.Render(HtmlTextWriter writer) +10
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +100
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
   System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +208
   System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +8
   System.Web.UI.Page.Render(HtmlTextWriter writer) +29
   System.Web.Mvc.ViewPage.Render(HtmlTextWriter writer) +56
   System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +100
   System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3060
Sep 9, 2010 at 8:10 PM

The simplified sitemap:

<?xml version="1.0" encoding="utf-8" ?>
<mvcSiteMap xmlns="http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-2.0" enableLocalization="true">

  <!-- Home -->

  <mvcSiteMapNode title="Home" controller="Home" action="Index" key="Home">
   
      <mvcSiteMapNode title="Cadastros &gt; Unidade de negocio" controller="UnidadeNegocio" action="Index" key="unidade" ParentKey="Home" />
      <!-- Usuario -->
      <mvcSiteMapNode title="Cadastros &gt; Usuario" controller="Usuario" action="Index" key="usuario" />
      <!-- Noticia -->
      <mvcSiteMapNode title="Cadastros &gt; Noticia" controller="Noticia" action="Index" key="noticia" />
      <!-- Evento -->
      <mvcSiteMapNode title="Cadastros &gt; Evento" controller="Evento" action="Index" key="evento" />
      <!-- Banner -->
      <mvcSiteMapNode title="Cadastros &gt; Banner" controller="Banner" action="Index" key="banner" />
      <!-- Lan�amento -->
      <mvcSiteMapNode title="Cadastros &gt; Lancamento" controller="Lancamento" action="Index" key="lancamento" />
      <!-- Colaborador -->
      <mvcSiteMapNode title="Cadastros &gt; Colaborador" controller="Colaborador" action="Index" key="colaborador" />   

    <!-- Imovel -->
    <mvcSiteMapNode title="Imoveis" controller="Imovel" action="Index" key="imovel" />

    <!-- Contatos -->
    <mvcSiteMapNode title="Contatos" controller="Contato" action="Index" key="contato" />
  </mvcSiteMapNode>

</mvcSiteMap>

The webconfig sitemap section:

    <siteMap defaultProvider="MvcSiteMapProvider" enabled="true">
      <providers>
        <clear />
        <add name="MvcSiteMapProvider"
             type="MvcSiteMapProvider.DefaultSiteMapProvider, MvcSiteMapProvider"
             siteMapFile="~/Web.Sitemap"
             securityTrimmingEnabled="true"
             enableLocalization="true"
             scanAssembliesForSiteMapNodes="false"
             skipAssemblyScanOn=""
             attributesToIgnore=""
             nodeKeyGenerator="MvcSiteMapProvider.DefaultNodeKeyGenerator, MvcSiteMapProvider"
             controllerTypeResolver="MvcSiteMapProvider.DefaultControllerTypeResolver, MvcSiteMapProvider"
             actionMethodParameterResolver="MvcSiteMapProvider.DefaultActionMethodParameterResolver, MvcSiteMapProvider"
             aclModule="MvcSiteMapProvider.DefaultAclModule, MvcSiteMapProvider"
         />
      </providers>
    </siteMap>

Sep 9, 2010 at 8:11 PM

I need to recognize the efforts with this project but it seems to have so many bugs that I'm wondering if there is any another solution to create sitemaps within ASP.NET MVC.

Coordinator
Sep 9, 2010 at 9:20 PM

Can you send me an email (maarten at phpexcel .net) with the source code throwing this issue? Really want to get it fixed...

Sep 9, 2010 at 10:30 PM
Edited Sep 9, 2010 at 10:33 PM

Hello again Maartenba,

It's a huge project with but the sitemap is simple as I posted here.

When I put in my masterpage <%= Html.MvcSiteMap().SiteMapPath(" &gt; ") %> the exception is throwed, even using scanAssembliesForSiteMapNodes="false".

Maybe can it be a problem with the VS webserver for debug?

I can send you the source but I think that you cannot be able to run it on your enviroment. There's the database, cryptographied passwords, users, twitter/facebook integration and a lot of other projects involved on the solution.

If you still want the source let me know, I'll be pleased to send it to you.

I downloaded the source code of the MvcSiteMapProvider if there's anything I can do to help, please, tell me.

Thanks a lot for your work.

Cheers

John

 

 

Coordinator
Sep 10, 2010 at 7:10 AM

Is there a specific page where this error occurs or just random?

Sep 10, 2010 at 8:38 PM

It happens in every page that uses the MasterPage.

Sep 10, 2010 at 10:43 PM

Maartenba,

I don't know but it working now. What I change was scanAssembliesForSiteMapNodes="true".

I tested with some dynamicNodes and it working like a charm.

Thanks a lot for your work, is there a paypal account where I can buy you a beer?

Coordinator
Sep 13, 2010 at 12:09 PM

That is strange, should work with that attribute set to false unless you have used a MvcSiteMapAttribute somewhere. Paypal account is paypal@phpexcel.net. Thanks in advance!