0

In a node, the title should be the name of the user logged into the system.

In addition I would like the result to be cached, because to retrieve the username I have to go to the database since the username is the email.

How to modify the title with the name of the logged in user and cache the result, but so that if another user logs in it will not load a cached page but a new page will be rendered to him.

ridermansb
  • 10,779
  • 24
  • 115
  • 226

1 Answers1

0

In v4 you can simply set the title in either your view or controller and it will be request cached for that user (no other user will see it).

@MvcSiteMapProvider.SiteMaps.Current.CurrentNode.Title = "My Username"

Of course, I am using CurrentNode as an example, you can do this with any node by walking the tree.

However, you will need to handle the caching of the username to prevent a database hit per request outside of MvcSiteMapProvider. You can do this by creating a cache item for each user, incorporating the username (as long as it is unique) into the key.

var key = "My Username";
var userName = HttpContext.Current.Cache.Item[key];
if (userName == null)
{
    userName = GetUserNameFromDB();
    HttpContext.Current.Cache.Item[key] = userName;
}
NightOwl888
  • 55,572
  • 24
  • 139
  • 212