Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserving values from nested DyanmicNodeProviders #277

Closed
chaoaretasty opened this issue Feb 10, 2014 · 4 comments
Closed

Preserving values from nested DyanmicNodeProviders #277

chaoaretasty opened this issue Feb 10, 2014 · 4 comments

Comments

@chaoaretasty
Copy link
Contributor

I have a sitemap where a person can have multiple roles along the following lines:

<mvcSiteMapNode title="Edit {0}'s Profile" area="Persons" controller="Profile" action="Edit" dynamicNodeProvider="DirectoryPersonProvider" >
    <mvcSiteMapNode title="Edit Roles" area="Persons" controller="Roles"  action="Index">
        <mvcSiteMapNode title="Edit Role" area="Persons" controller="Roles" action="Edit" dynamicNodeProvider="DirectoryPersonRoleProvider" />
        <mvcSiteMapNode title="Add Role" area="Persons" controller="Roles" action="Add"/>
    </mvcSiteMapNode>
</mvcSiteMapNode>

In order to get a map like:

Edit Person 1's profile
    Edit roles
        Edit Person 1's first role
        Edit Person 1's second role
        Add Role
Edit Person 2's profile
    Edit roles
        Edit Person 2's first role
        Edit Person 2's second role
        Edit Person 2's third role
        Add Role

DirectoryPersonProvider Works fine, it queries the database and inserts nodes adding a personid routevalue for each. When DirectoryPersonRoleProvider runs I want to be able to query for all roles for a person but I can't find anyway to get the personid out of the parent node the provider is given. I've tried combinations of inherit or preserve route values but nothing seems to work. I think DirectoryPersonRoleProvider is running once per XML sitemap element rather than once per node generated by DirectoryPersonProvider.

Worst comes to worst I can generate the whole tree from DirectoryPersonProvider but this takes a lot of the nodes out of the XML file.

@NightOwl888
Copy link
Collaborator

I think what you are after is the buggy nested dynamic recursion behavior that existed in v3, although I never thought I would have anyone ask for it. You can enable that behavior with the configuration setting in web.config, although I don't recommend it.

<appSettings>
    <add key="MvcSiteMapProvider_EnableSiteMapFileNestedDynamicNodeRecursion" value="false"/>
</appSettings>

This causes the child dynamic node provider to be called N+1 times, where N is the number of nodes returned from the parent dynamic node provider. Don't ask me what the +1 is for, I couldn't figure that out. This was a major source of performance issues in v3.

Before you do that though, there is a better option for this use case that could eliminate the need for the dynamic node provider entirely. You can only use this if you don't intend the pages to be indexed by search engines and don't want all of your child items to appear in the menu, but fortunately for administration pages (CRUD operations) that is the normal case.

You can just declare a single set of nodes in your XML with the preservedRouteParamters element set to the id and then this single set of nodes will always match every record in your database. You then need to use the SiteMapTitleAttribute to fix the title and the FilteredSiteMapNodeVisibilityProvider to fix the visibility on the menu. There is a whole blog post about this as well as a downloadable working demo that explores these options titled How to Make MvcSiteMapProvider Remember a User's Position.

@chaoaretasty
Copy link
Contributor Author

Actually that's exactly what I wanted to hear. I'm currently doing a big upgrade from a heavily abused v3, in fact there are a lot of places I currently do things the way you mentioned for performance reasons but thought it was not a recommended method vs DynamicNodeProviders. As performance was mentioned as something that's improved in recent versions and that large numbers of nodes were not an issue I thought I'd change this around. Looks like I'm fine not making this change anyway.

@NightOwl888
Copy link
Collaborator

Well, there is still a hard limit on the number of nodes that I plan to work on in v5 (see #258). I wouldn't recommend using more than about 10,000-15,000 nodes total in v4. Fortunately, that is enough for most people and using preservedRouteParameters can reduce the number in a lot of scenarios.

@chaoaretasty
Copy link
Contributor Author

Yeah I was hitting that on profile view pages alone. Was worried for when I
started adding other dynamic entries too.

I'm currently handling the search engine sitemaps by adding them in to
linked sitemap files manually.
On 10 Feb 2014 13:04, "NightOwl888" [email protected] wrote:

Well, there is still a hard limit on the number of nodes that I plan to
work on in v5 (see #258#258).
I wouldn't recommend using more than about 10,000-15,000 nodes total in v4.
Fortunately, that is enough for most people and using
preservedRouteParameters can reduce the number in a lot of scenarios.

Reply to this email directly or view it on GitHubhttps://github.com//issues/277#issuecomment-34628419
.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants