Mental Jetsam

By Peter Finch

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.

<html>
<body>
<%
dim dos, env
set shell= CreateObject ("WScript.Shell")
set enviro = shell.Environment ("PROCESS")
whoami = " " & enviro("COMPUTERNAME")
response.write "Current server " & whoami
%>
</body>
</html>
Advertisements

2 Responses to “Classic ASP code to print current server name”

  1. Pedro said

    Thanks, just what I was looking for.

  2. felix said

    super code, thanks a bunch!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: