2

I found in one of my old asp classic pages a line of vbScript code beginning with // and it was an error (commenting a line with // instead of ').

I noted anyway that the mistaken commented line works as a correct commented line. Someone knows why ?? Thanks a lot Leonardo

I made a small example taken from that old code:

<%
Response.Write "<u>testAsp.asp</u><hr/>" 
V_Password="pwd"
//V_Password = Str2Hex(V_Password)

Response.Write "V_Password=" + V_Password + "<br/>"
Response.Write "V_Password(hex)=""" + Str2Hex(V_Password) + """"

function Str2Hex(s)
' -- converte stringa di byte (non caratteri ascii!!) in formato esadecimale
'
'    The Asc function returns the ANSI character code corresponding 
'    to the first letter in a string.
'    The AscB function is used with byte data contained in a string. 
'    Instead of returning the character code for the first character, 
'    AscB returns the first byte. 
'    AscW is provided for 32-bit platforms that use Unicode characters. 
'    It returns the Unicode (wide) character code, thereby avoiding 
'    the conversion from Unicode to ANSI.

  dim k, out, MultiByte
  out=""
  for k=1 to len(s)
    'response.Write("|" & hex(ascb(Mid(s,k,1))) & "|<br>" & vbCrLf)
    out=out & hex(ascb(mid(s,k,1)))
  next
  Str2Hex="0x" & out
  'response.write(out & vbCrLf)
end function

%>

This is the produced output:

enter image description here

As you can see the asp page is in vbScript and contains also correct vbscript comments...

1 Answers1

3

Update

So I've done a bit of digging since you posted the example code and confirm that in a Classic ASP environment the code runs without error and appears to behave like a comment.

What I can confirm though is this is specific to a Classic ASP environment. If I try to run the example using wscript.exe as the host instead of Classic ASP I get the following error;

Microsoft VBScript compilation error: Expected statement

The only conclusion I can come to is it's a peculiar side-effect of support for both VBScript and JScript that means the ASP pre-processor doesn't cause the VBScript Runtime to throw a compilation error.

The likelihood is it's an accident that never got picked up because the page didn't force a compilation error as running the VBScript natively would.


Original Answer for Prosperity

Chances are the Classic ASP page was set to use JScript instead of VBScript. Both are available as default Active Scripting languages out if the box.

It might not always be clear what is in use as what scripting language is used by default can be set at the IIS website level rather than using the @language directive or a <script runat="server"> block.

Comments in VBScript come in two flavours, there are the Rem statement and the ' character. Starting a line of code with either will prevent the execution of that code in the script.

REM This is a comment
'This is also a comment
Response.Write "Hello"

Comments in JScript also come in two flavours, there is // for single-line comments and /* */ to span multiple lines.

// This is a comment
/*
This is also a comment
*/
response.write("Hello");

Useful Links

user692942
  • 16,398
  • 7
  • 76
  • 175
  • Your response is wise. This old code worked in production initially on IIS 6, and now on IIS 10. In my case i included the asp code to debug in a small ampty project in visual Studio 2019. Now i think that i have to control iis express configuration. As you can see in the example the execution does not stop at the //V_Password= ... – Leonardo Danza Apr 04 '20 at 16:42
  • 1
    I've removed that because it was just a guess but I've managed to research it and VBScript variables cannot contain forward slash characters so that can't be it. – user692942 Apr 04 '20 at 16:52