Category Archives: ASP

ASP, ServerVariables, Server_Name, Windows 2003, IIS6

We’re in the process of upgrading our webservers to Windows 2003 and thus IIS6. One of the issues we ran into was that the Server_Name key of the ServerVariables collection in VBScript started returning the computer name of the machine rather than the host name of the website. I spent a couple hours googling and found nothing, my recent hire found the hot fix on in about 5 minutes today (which shows how important good google skills are). In short, there’s a security issue with IIS (surprised?) whereby sending a GET request to an IIS web server without sending a host header would result in the web server returning the IP address of the web server in the content location field of the response TCP header. The easy fix is to run:

cscript adsutil.vbs set w3svc/UseHostName false

which modifies all IIS web sites to return the website host name rather than the machine name / IP address when getting the Server_Name key of the ServerVariables collection.

ASP, Java, Cookies and URLEncode

One of the bugs I tracked down a couple months ago dealt with the different ways in which ASP and Java handle URL encoding in a cookies. ASP automatically encodes and decodes cookie values (without you telling it too even though it the Server object has a method ‘URLEncode’ which does the same job) while Java requires that you explicity use the URLDecoder and URLEncoder, otherwise it sends the cookie values without encoding them first, which in my case lead to an interoperability problem (one assumes URL encoding of cookie values, one doesn’t).

But then it gets weirder. The encoding that ASP automatically applies is different than the encoding that Java applies. For example, in ASP you’d write something like this to set a cookie with my email address:

Response.cookies("encoded") = ""

which would then result in this:


where in Java you’d have something like this:

String email = "";
String encoded = URLEncoder.encode(email, "UTF-8");
res.addCookie(new Cookie("encoded", encoded););

which results in this:

So why does ASP encode the period as %2E and Java leave it alone? The Microsoft documentation for the ASP Server object contains very little documentation about the URLEncode method other than to say that the URLEncode method

… applies URL encoding rules, including escape characters, to a specified string.

(which could be a teensy bit more helpful, must have been a programmer writing that documentation). On the other hand, the Java URLEncoder class documenation says that the special characters “.”, “-“, “*”, and “_” are not to be encoded according to the HTML specification, which itself cites RFC 1738 which says:

…the special characters “$-_.+!*'(),”, and reserved characters used for their reserved purposes may be used unencoded within a URL.

which seems to me to imply that the ASP Cookie object is wrong (ie: it should leave the period alone in the email address). And beyond that, it’s pretty aggressive in assuming that I want to encode the data in my cookies. Am I missing something? How do other languages (PHP, Python, Perl, etc..) implement the same functionality? Aren’t web applications fun?

Scripting in ASP with Java

I’m working on a project right now that involves a store written in Java using Struts and a sister site written in ASP. One of the features of the store requires that the sister site use some logic written in Java, which you might think is impossible. Turns out (doesn’t it always?) that you can quite easily use simple Java methods and objects within ASP from VBScript. I found two articles (and really only 2) that introduced the use of a simple Java class from ASP (which you can read here and here). Here’s a Hello World example:

package org.mycompany;
public class TestClass {
 public String sayHello(String name) {
   return "Hello " + name;

compile this and then you save the resulting class file to:
So the above example would result in a file saved as:
From ASP, you can then use the following syntax:

Dim obj
set obj = GetObject("java:org.comcompany.TestClass")
result = obj.sayHello("Aaron Johnson");
set obj = nothing

Couple of items of note:

a) the use of what Microsoft calls a “Java Moniker” allows you to use a Java class without first registering it with the system, which is nice (so you got that going for ya),

b) just like a servlet container, if you make changes to the Java class file while the application is running, you must restart the container, which in this case is IIS,

c) you must (as I mentioned before) make sure to place the compiled class file in the appropriately named subdirectory of %Win%/Java/TrustLib/, where %Win% is usually C:\windows\ or C:\winnt\,

d) you can’t use static methods in your Java class if you want to be able to call those methods from VBScript. It appears (from my quick attempts) that the VBScript engine first creates an object using the default constructor and then calls the given method on that instance. Modifiying the method to be static resulted in a runtime error, and finally

e) your code must work in the Microsoft JVM (I think), which isn’t being supported past September 2004.


Worked around a nasty issue on an ASP site today, I’m was using the MSXML2.XMLHTTP.4.0 object to post an XML packet to a SOAP server. Worked great on our development and staging servers, but I installed it (the app) on the client server today and get this… calling the send() method completely hangs IIS, you can’t stop the service, you can’t restart the service. Here’s the code snippet in question:

Dim objHTTP
Set objHTTP = Server.CreateObject(“Msxml2.XMLHTTP.4.0”) “POST”, “http://yourhost/”, false
objHTTP.setRequestHeader “Content-Type”, “text/xml”
objHTTP.setRequestHeader “SOAPAction”, “urn:myserver/soap:ThisName/thisMethod”
objHTTP.send xmlpacket
strReturn = objHTTP.responseXML.xml

The behavior I’m seeing is that the HTTP request doesn’t even get sent to the remote server, the IIS process becomes unusable, and restarting the W3/IISAdmin services don’t work. I’m using MSXML 4.0 Service Pack 2 (available here).

Server-Side Flash Detection Using BrowserHawk @ DEVNET

I wrote an article for Macromedia Devnet which was just published today! Check it out here: Server-Side Flash Detection Using BrowserHawk. If you’ve never used BrowserHawk before, it’ll be a good introduction. However, if you’ve used it with ColdFusion, you should definitely read it, I was able to use BrowserHawk 4J (the Java version) with CFMX rather than using the ASP bridge (which was and is required if you want to access the extended properties of BrowserHawk in versions of ColdFusion prior to MX).

I should thank Shena at my work for bringing it up as an option (she contacted Macromedia originally), thanks Shena!

great introduction to using SOAP, ASP and VB

After posting an order on the ecommerce site I’m working on, we have to get tax information and authorize the users credit card. Both of these functions (Vertex for tax and viaWarp for Credit Cards) live on a different machine than the webservers in the cluster, so I thought it made sense to use SOAP to send and retrieve messages re: Credit Cards & Tax information (especially since the IT department would like to re-use whatever we build with other pieces of their infrastructure). This is a great introduction to using SOAP, ASP and VB.