This is a migrated thread and some comments may be shown as answers.

[Solved] Menu: Bind Sitemap inside a MasterPage

11 Answers 448 Views
Menu
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Dominic
Top achievements
Rank 1
Dominic asked on 10 Dec 2009, 11:23 AM

Hello,

how can i bind the web.sitemap on the menu control inside the Site.master. I have studied the samples but all my tests end in a KeyNotFoundException.

Best regards

11 Answers, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 10 Dec 2009, 02:42 PM
Hello Dominic,

To achieve your goal you will need to register the required SiteMap in the Global.asax like so:
SiteMapManager.SiteMaps.Register<XmlSiteMap>("examples", sitemap => sitemap.LoadFrom("/Web.sitemap"));

The second step you should done is to add PopulateSiteMap attribute to all controllers, because they are responsible for populating VIewData:
[PopulateSiteMap(SiteMapName = "examples", ViewDataKey = "telerik.mvc.examples")]

For example you can examine the Navigation.ascx file in the Telerik.Mvc.Web.Examples project.

All the best,
Georgi Krustev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Dominic
Top achievements
Rank 1
answered on 10 Dec 2009, 05:17 PM
Hello,

great it works.
Is there a way or sample to use a sitemap ( e.g. http://mvcsitemap.codeplex.com/ ) for securityTrimming with roles?

best regards
0
Georgi Krustev
Telerik team
answered on 11 Dec 2009, 10:39 AM
Hi Dominic,

There is no such property, but there should be no problem, because our sitemap internally checks which user is authorized and which is not. Please give a try and let me know if some problems raise.

Greetings,
Georgi Krustev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
sL342799
Top achievements
Rank 1
answered on 12 Jan 2010, 09:41 AM
Hi,

Does anybody have a working example of an MVC site with Menu/Panel bound to a sitemap? Looking for strip down version  - checked the telerik examples it all works... but is confusing...

Thanks!
0
Jose Ardila
Top achievements
Rank 1
answered on 05 Feb 2010, 10:33 PM
Hi.

I test the sitemap with the roles attribute and doesn't work.

Web.sitemap

<?xml version="1.0" encoding="iso-8859-1" ?>
<siteMap>
  <siteMapNode title="Principal" controller="Home" action="Index">
    <siteMapNode title="Configuraciónes">
      <siteMapNode title="Datos basicos" roles="Usuario">
        <siteMapNode controller="DatosBasicos" action="Editar/3" title="Editar" roles="Usuario" />
      </siteMapNode>
      <siteMapNode title="Usuarios">
        <siteMapNode controller="Usuarios" action="Crear" title="Crear" />
        <siteMapNode controller="Usuarios" action="Index" title="Editar" />
      </siteMapNode>
    </siteMapNode>
  </siteMapNode>
</siteMap>

Another thing is when i test the application i change the sitemap and in order to see the changes i must delete the .dll files of the application, rebuild the solution and test again. I s very tedious task.

Any suggestions?

Best Regards.

Jose Luis Ardila
0
Georgi Krustev
Telerik team
answered on 08 Feb 2010, 07:44 AM
Hello Jose,

Thank you for pointing this issue.

I will forward this information to our developers for further investigation and notify you in short time what are there findings.

Every registered sitemap, which is registered, is cached. Hence if you are using localhost test environment you should stop the localhost server to apply the changes.

Regards,
Georgi Krustev
the Telerik team

Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
0
Matthew Dressel
Top achievements
Rank 1
answered on 10 Feb 2010, 10:21 PM
Shouldn't I also be able to simply add the PopulateSiteMap attribute to the class and have it apply to all of the controllers in the class.  It seems quite tedious to add this property to all controllers when what I woudl like is to have a common sitemap for my entire site.  In my case I have a ControllerBase class which is where I would like to have all of this functionality built.  So an example migh tbe:

    [PopulateSiteMap(SiteMapName = "mainSiteMap", ViewDataKey = "mainSiteMap")]  
    public class ControllerBase : Controller  
    {  
        public ControllerBase()  
            : this(new T())  
        { }  
 
        public ControllerBase(T repository)  
        {  
            if (!SiteMapManager.SiteMaps.ContainsKey("mainSiteMap"))  
            {  
                SiteMapManager.SiteMaps.Register<XmlSiteMap>("mainSiteMap", sitemap => sitemap.LoadFrom("~/Content/Main.sitemap"));  
            }  
 
        }  
    } 
0
Kazi Manzur Rashid
Telerik team
answered on 16 Feb 2010, 05:05 AM
Hello everyone,

Please allow me to clarify few issues:

1. Our MvcSiteMap is completely new and has been written from scratch, So things that are applicable in ASP.NET 2.0 may not be available in our SiteMap. For example, in ASP.NET 2.0 Sitemap you can assign roles in the SiteMapNode, but in MVC it is recommended to decorate your controller action with Authorize attribute with your preferred roles, in this case our sitemap checks whether the visiting user has the permission by reading that matching action attribute.

2. As mentioned that it is a complete new version, so there quite a few things that you will get out of the box. For example if you visit /SiteMap.axd it will render the search engine xml which you will improve your SEO story.

3. Yes adding the PopulateSiteMap to every controller is some what a pain in the neck but this is how the ASP.NET MVC has been designed. If you are using MVC 2 I would suggest to render the sitemap dependent UI with the new RenderAction method, this will eliminates the above issue.

Greetings,
Kazi Manzur Rashid
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Matthew Dressel
Top achievements
Rank 1
answered on 16 Feb 2010, 03:48 PM
Kazi,

Thank you very much for this information.  This is very helpful

  1. I did not realize that using the autorize attributes would work as you suggested.  Perhasp that is an area which could be expanded in the examples or reference information.
  2. To expand on my previous post, I have found that, infact you do not need to add the PopulateSiteMap attribute to each action.  Instead if you simply add the attibute to a base class then all actions in that class or sub classes will have the attribute applied.  I also will be looking further into the RenderAction functionality as it seems to be a more "straight forward" approach.

With all of that said I am still having issues with the menu displaying information from the sitemap file.  I am utilizing very similar code to what I posted earlier and I have verified that as the Grid.BindTo method is being called the ViewData contains the correct dat with the key "mainSiteMap"  However, nothing is displayed.  Do you have any idea as to why this is happening?

Thanks for any help you can provide.

0
Kazi Manzur Rashid
Telerik team
answered on 18 Feb 2010, 08:15 AM
Hi Matthew Dressel,

Okay let me create a test application for you.

Greetings,
Kazi Manzur Rashid
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Derek Hunziker
Top achievements
Rank 1
answered on 07 Jul 2010, 11:11 PM
I too didn't realize that you could decorate your ActionResults to achieve security trimming. I think you guys should advertise that feature as it's extremely powerful.

Also, as Matthew pointed out, you can derive all of your controllers from a BaseController class that's sporting the PopulateSiteMap attribute. This is much easier to implement and manage IMO... it might be something worth mentioning in the docs.

Thanks,

-Derek
Tags
Menu
Asked by
Dominic
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Dominic
Top achievements
Rank 1
sL342799
Top achievements
Rank 1
Jose Ardila
Top achievements
Rank 1
Matthew Dressel
Top achievements
Rank 1
Kazi Manzur Rashid
Telerik team
Derek Hunziker
Top achievements
Rank 1
Share this question
or