Adding route values just in the context of the current request (via SiteMapPreserveRouteData?)

Feb 18, 2011 at 9:10 AM

Hi,

I have a question for my better understanding.
What i want to archieve is rendering a menu where some user-specific route parameters should be added: The user opens a "product" of a specific Id, and this Id should be added to multiple links, like:
..../ShowDetails?Id=MY_ID
..../Edit?Id=MY_ID
...

MY_ID is user-specific, so different users must have different values, and must not see the Ids of the other requests..

I looked into the code of the class SiteMapPreserveRouteDataAttribute, and I can find there:

 var node = SiteMap.CurrentNode as MvcSiteMapNode;

but: this Node is of a static character (for all requests = users), so changing it there by adding route values CHANGES THE ONE-AND-ONLY static Node.
If I add my request-specific Id there, all further requests have an ady changed node, or am I wrong here?

How can I add the Ids just in the context of the current request?

Coordinator
Feb 18, 2011 at 10:04 AM

You can use the same technique as in SiteMapPreserveRouteDataAttribute, only ensure that after a request the added parameter is removed again. But I would not recommend doing it like this and instead store the ID osmewhere in a cookie or sssion...

Feb 18, 2011 at 10:21 AM

I thought about this. But this is not thread safe.

For example, if I have 10 Nodes:

When a first request comes in, its thread begins to change the nodes, beginning from 1, 2 ... .
Them another requests comes in, just a short time after the first, and the first has not yet finished the last. The second request changes also, starting fom 1, 2 ..., thus overwriting the node attributes from the first request.

The result is a mixture, with different IDs. Or is this point of view not correct, and I missed something ?

Having a web application with multipl concurrent requests this scenario is not only academic.

 

Do you have any solution for this?

mausoma

Coordinator
Mar 25, 2011 at 8:41 PM

No... The underlying SiteMapProvider (from ASP.NET) provides this behaviour.