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

SiteMapPath not taking cookie-less uri into account #407

Closed
vtherry opened this issue Aug 24, 2015 · 2 comments
Closed

SiteMapPath not taking cookie-less uri into account #407

vtherry opened this issue Aug 24, 2015 · 2 comments

Comments

@vtherry
Copy link

vtherry commented Aug 24, 2015

Hi,

we are facing an issue while upgrading my project from MVC3 to MVC5 (and so MvcSiteMapProvider 2.x to MvcSiteMapProvider 4.x).

In our project, we are obliged to use cookie-less uris and everything was working fine with MvcSiteMapProvider 2.x. Our SiteMap path was displaying correctly with the session ID in the url but when upgrading to MVC5 and MvcSiteMapProvider 4.x, the session ID is not there now.

We have also lost our preserved parameters :(

I was able to reproduce it in a very simple project.
Here is a gist with my configuration : https://gist.github.com/vtherry/2403b94e53c6a96c8bda

Please let met know if I am using the framework the wrong way or if cookie-less sessions are not supported anymore but there is still the issue with preserved parameters not being displayed in uris :(

Thank you for your support !
Vincent

@NightOwl888
Copy link
Collaborator

Hello.

The official stance of Microsoft is that cookieless sessions are not supported in MVC.

If you still want to go down that road, the thing that changed which causes the cookieless sessions not to work is that a fake HttpContext based on the home page is used to resolve the URLs. This keeps values from bleeding through unintentionally from the current context into the generated URLS, which some people find confusing (see #213).

You can use the actual HttpContext of the current page by setting the includeAmbientValuesInUrl attribute/property of the node, which allows the session state key to be written to the URL. Unfortunately, this has to be applied to every node in order to make it work, though.

v2 and v3 had a bug that many people were relying on in their configuration - route values that were written on a request went into the primary cache. This made it seem like it saved the ids for the current user across requests when navigating around the site. However, the cache was shared between all users so the next user that came along would overwrite the RouteValue settings. This has been fixed in v4, but is also a source of confusion because configurations that seemed to work before no longer work.

I have created a demo project based off of your configuration showing one way you could get your breadcrumbs to work using Preserved Route Parameters. There is also a post titled How to Make MvcSiteMapProvider Remember a User's Position that goes into some detail about how this works (which has more demos).

@vtherry
Copy link
Author

vtherry commented Aug 25, 2015

Hi,

Thank you for your quick answer !
It is much appreciated !

With your comments I was able to understand the behavior of the preservedRouteParameters attribute.
I was using ID properties for different entities and trying to remember them in the breadcrumb, but only the ID in the uri was showing in node's urls. Now I got it and I pass my parameters to the actions keeping names identical.

The SessionID is working well with parameter includeAmbientValuesInUrl now.

So ... many thanks ! :) I was able to fully upgrade my project to MVC5.
Vincent

@vtherry vtherry closed this as completed Aug 25, 2015
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