转义 asp/vbscript 脚本标签

Escape asp/vbscript script tags

如何转义asp指令输出

所以我需要使用 asp 标签打印到页面字符串

<%
response.write "<%=Count%>"
%>

但是我得到错误

Microsoft VBScript compilation error '800a0409'
Unterminated string constant

那么如何打印脚本标签呢?

所以我需要 <%=Count%> 而不是 Count

有什么方法可以代替?

<%
    response.write "<" & "%=Count%" & ">"
%>

方法是在代码块中使用 <script> 标签而不是 <% ... %>

<script language="vbscript" runat="server">
    Response.Write "<%= Count %>"
</script>

输出:

<%= Count %>

您只需要确保在尝试使用 Response.Write() 像这样的东西之前 HTML 进行编码;

这里我使用 % 的 HTML 编码值 &#37 来阻止 VBScript 运行-time 吐出它的虚拟 (但你甚至可以使用 &lt; 代表 <&gt; 代表 > 的任何东西,正如建议的那样).

<%
Response.Write "<&#37=Count&#37>"
%>

输出:

<%=Count%>

或者,您可以通过 shorthand Response.Write:

简单地使用 &lt;&gt; 字符代码
<%= "&lt;%= Count %&gt;" %>