【问题标题】:asp classic vBscript line beginning with //以 // 开头的 asp 经典 vBscript 行
【发布时间】:2020-04-07 14:05:42
【问题描述】:

我在我的一个旧的 asp 经典页面中发现一行以 // 开头的 vbScript 代码,这是一个错误(用 // 而不是 ' 注释一行)。

无论如何,我注意到错误的注释行作为正确的注释行起作用。 有人知道为什么吗?? 非常感谢 莱昂纳多

我从那个旧代码中做了一个小例子:

<%
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

%>

这是生成的输出:

如您所见,asp 页面在 vbScript 中,并且还包含正确的 vbscript cmets...

【问题讨论】:

  • 确定是 VBScript 而不是 JScript,两者都可以作为 Active Scripting 语言使用 Classic ASP 开箱即用?
  • 如果你能提供一个关于你所看到的行为问题的最小例子会有所帮助。
  • 是的,我确定。没有@language 指令。

标签: vbscript asp-classic


【解决方案1】:

更新

因此,自从您发布示例代码并确认代码在经典 ASP 环境中运行时没有错误并且表现得像注释后,我已经进行了一些挖掘。

我可以确认的是,这是特定于经典 ASP 环境的。如果我尝试使用 wscript.exe 作为主机而不是 Classic ASP 来运行示例,我会收到以下错误;

Microsoft VBScript 编译错误:预期语句

我能得出的唯一结论是,它是同时支持 VBScript 和 JScript 的一种特殊副作用,这意味着 ASP 预处理器不会导致 VBScript 运行时引发编译错误。

很可能这是一个从未被发现的意外,因为该页面没有像本地运行 VBScript 那样强制编译错误。


繁荣的原始答案

Classic ASP 页面可能被设置为使用 JScript 而不是 VBScript。两者都可以作为默认的 Active Scripting 语言使用。

可能并不总是清楚正在使用什么,因为可以在 IIS 网站级别设置默认使用的脚本语言,而不是使用 @language 指令或 &lt;script runat="server"&gt; 块。

VBScript 中的注释有两种形式,有Rem 语句和' 字符。使用其中任一开始一行代码将阻止该代码在脚本中的执行。

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

JScript 中的注释也有两种形式,// 用于单行 cmets,/* */ 用于跨多行。

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

有用的链接

【讨论】:

  • 您的回答是明智的。这个旧代码最初在 IIS 6 上用于生产,现在在 IIS 10 上运行。在我的情况下,我在 Visual Studio 2019 的一个小型项目中包含了用于调试的 asp 代码。现在我认为我必须控制 iis express 配置。正如您在示例中看到的,执行不会在 //V_Password= ... 处停止
  • 我已将其删除,因为这只是一个猜测,但我已经设法对其进行了研究,并且 VBScript 变量不能包含正斜杠字符,因此不可能。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-11-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多