Sunday, March 19, 2017

Passing Parameters to XenDesktop by Rewriting the StoreFront ClientName


A recent client had the following business requirements:

1) To logon, enumerate and launch a XenDesktop from within their corporate intranet, and

2) To pass department/project information to the desktop. This was necessary so that the correct network drives were mapped for the session.

The first requirement was easily met by using the StoreFront Web API to embed StoreFront functionality into their intranet. The second requirement, however, was a bit more involved, as the same user could possibly be working on multiple projects simultaneously, and would therefore require different drive mappings for each.

Enter the StoreFront Store Customization SDK. The Store Customization SDK has predefined "customization points" which allow you step in and apply custom logic to modify enumerated resources, change launch parameters, and to modify device information. 

You can download the latest version of the Store Customization SDK here.

For an introduction to the SDK, see Citrix Principal Architect Simon Frost's blog post: Introducing the StoreFront Store Customization SDK. You can also check out his Synergy Developer Exchange Series video StoreFront Store Customization SDK.
One such field that can be modified via the Store Customization SDK is the session Clientname, which is easily accessed from within the XenDesktop session. Simon made modification of the Clientname quite easy with the release of his blog post and accompanying DLL Rewriting the Session ClientName from StoreFront. Alas, none of the many tokens defined in the DLL would support passing a dynamic parameter such as department or project information. However, since Simon was kind enough to also supply the source for his DLL, I was able to satisfy that business requirement by extending his DLL to incorporate HTTP headers into the ClientNameRewriteRule.


Simply use the token $H’header name’ (single quotes) within the ClientNameRewriteRule where you would like the value of the specified header placed (please refer to his blog post for a detailed explanation of the ClientNameRewriteRule).

For example, if I wanted the ClientName to contain the user’s roaming status (“I” for internal, and “E” for external), and the value of the Department header, the rule might look something like:

<appSettings>

    <add key=”clientNameRewriteRule”  value=”$R-$H’Department’ “ />

</appSettings>



If the value if the Department header was Dept007, then the ClientName would look like:

 
You must keep in mind the ClientName restrictions - the total length of the result must be 20 characters or less – anything longer will be truncated, and may not contain any of the following characters: “/ []:;|=\,+*?<>.
You must also set the value of overrideIcaClientName to “On”. For newer versions of StoreFront, you can find the setting in the GUI under Configure Store Settings | Advanced Settings. For older versions of StoreFront, see Simon’s blog post for manually modifying the configuration file (always make sure that the GUI console is not open when manually modifying any of the configuration files).
There is one final (but essential) requirement. For security reasons, StoreFront will not forward any unknown headers, so you must add your new header to the StoreFront whitelist:
  • Backup web.config in your <Store>Web directory.
  • Find the <communication> section (under <webReceiver> | <serverSettings>).
  • Add the highlighted lines:

  • Save the file ... an IISRESET is not required.