Tuesday, July 28, 2020

Stupid Citrix Trick #6: Showing the Web Server Name in StoreFront

Problem: Sometimes when users are logging on through the StoreFront web page, you need to know what web server they are reaching.

Solution:  This is a pretty common thing, mostly for troubleshooting or finding other inconsistencies between how two StoreFront web servers are behaving.  When I started out a co-worker would just hard code the store name in the StoreFront HTML.  He couldn't figure out why, after he replicated from one server to another, only one server name showed up!

The solutions I found online typically involved setting a value in Internet Information Services that's unique to that server and the retrieving it, but I believe I've found a better way.

First you're going to want to create a file called GetServerName.aspx, and if you want the domain too then you may want to create GetServerDomain.aspx.  You can do that all in one file, but having separate ones gives you a little flexibility in how you display it.

Since these files will only be used on the web page and not the Citrix client, we'll put them in the customweb folder.

What I realized was that the server name and domain are available in environment variables on the server, and we can use very simple ASP.NET code to query and return them.  Here's GetServerName.aspx:

<%@ Page Language="C#"%>
<%=Environment.GetEnvironmentVariable("COMPUTERNAME")%>

That's the whole file.  GetServerDomain.aspx is almost as simple:

<%@ Page Language="C#"%>
<%=System.Net.NetworkInformation.IPGlobalProperties.GetIPGlobalProperties().DomainName%>

As I said, you drop those two files in the customweb folder, and then you go to the custom folder and edit script.js.

I am not a Javascript expert. I know just enough endanger my livelihood, but I always like to make sure my Javascript variables have some value, because if they don't it could cause issues in the code. So let's set some variables to an empty string:

var ServerName = ""; // The name of this StoreFront server.
var ServerDomain = ""; // The DNS name of the StoreFront server's domain.

Next we're going to jump down to a portion of script.js where the function CTXS.Extensions.afterDisplayHomeScreen gets called.  This is when the home screen has already been loaded, and that's when we want to make the changes.  Here's the code to insert the variable:

CTXS.Extensions.afterDisplayHomeScreen = function (callback)
{
    // Get the server name.
    $.ajax(
    {
        async: false,
url: "customweb/GetServerName.aspx",
success: function(Name)
{
ServerName = Name;
}
    });

    // -----------------------------------------------------------

    // Get the server domain.
    $.ajax(
    {
async: false,
url: "customweb/GetServerDomain.aspx",
success: function(Domain)
{
ServerDomain = Domain;
}
    });
};
 
Again, my Javascript skills are somewhat rudimentary.  In particular this is considered poor practice because it's a synchronous operation, and if there are any delays getting the data back it could cause problems.  Use at your own risk, and your mileage may very, but this has worked in our environment.

(Also, if someone has a simple method for doing an asynchronous callback, please drop it in the comments to I can be "with it" like all the cool kids.)

No comments:

Post a Comment