Sitecore Swamp

Dive in the Sitecore Swamp

NAVIGATION - SEARCH

My Toolbox - 2018

As working as a consultant, often to spin up a new development environment. Besides the VS and SQL, there are plenty of useful tools/extensions need be installed as well. Here's a list of the tools which I can't live in my coding life without:

-. Notepad++
-. 7zip
-. Resharper (dotPeek and dotTrace), undoubtable the No 1.
-. Test Driven, right click and run any method
-. CodeCompare, after years of WinMerge, this one has became my favorite code compare tool, and sorry 
-. Winmerge, still have a place here as the folder comparison is a thumb-up.
-. Wireshark, never disappoint you if you know how to talk to it (query and filter)
-. Postman is new here, as it's easy play with services
-. Fiddler, Chrome has replaced most of uses Fiddler
-. Ditto, ctrl+~ prompt the list of clipboard history, simple and useful (thanks to Ke and Bruno)
-  TOC
 

Sitecore Virtual User - Can't Save Profile Property

It's quite common to create some custom properties and save them for virtual users. I just encountered a problem that the profile properties are not saved, even specifically calling virtualUser.Profile.Save().

After a couple hours code debugging and dot peeking, found the cause of the problem: 

The custom profile properties are saved into Core db - ClientData table (since Sitecore 8.1.1). The identifier is the session key. In Sitecore code, it's using WebUtil.GetSessionID() to generate the key. Here is the peeked code:

    public static string GetSessionID()
    {
      HttpContext current = HttpContext.Current;
      if (current != null && current.Session != null)
      {
        if (current.Session.IsNewSession && Settings.Performance.ForceASPSessionIDPersist)
          current.Session["__forceSessionPersist"] = (object) "dummy";
        return current.Session.SessionID;
      }
      string sessionIdCookieName = WebUtil.GetSessionIdCookieName();
      Assert.IsNotNull((object) sessionIdCookieName, "key");
      if (!Context.IsUnitTesting)
        return WebUtil.GetCookieValue(sessionIdCookieName);
      return WebUtil.GetCookieValue(sessionIdCookieName, "unittests.net_sessionid");
    }

If this is the initial request, the session can be null, and, of course, there no session cookie either. In this case, WebUtil.GetSession() returns empty string, which causes nothing can be persisted into database.