Mental Jetsam

By Peter Finch

Archive for January, 2008

Classic ASP code to print current server name

Posted by pcfinch on January 29, 2008

Some simple ASP classic (VB script) code to print out the current server name. Unlike using the Request.ServerVariables(“SERVER_NAME”) function, this method returns the server that the ASP code actually ran on instead of the hostname passes in the URL. This is useful if there is number of backend servers running through a load balancer with “session affinity” and you what to know which one you are talking to.

dim dos, env
set shell= CreateObject ("WScript.Shell")
set enviro = shell.Environment ("PROCESS")
whoami = " " & enviro("COMPUTERNAME")
response.write "Current server " & whoami

Posted in VBScript | 2 Comments »