Search code examples
vbscriptasp-classic

Escape asp/vbscript script tags


How to escape asp directive output

So i need print to page string with asp tags

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

But I get error

Microsoft VBScript compilation error '800a0409'
Unterminated string constant

So how to print script tags?

So i need get <%=Count%> not Count

There are any way instead of ?

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

Solution

  • You just need to make sure you HTML encode before attempting to use Response.Write() something like this;

    Here I use the HTML encoded value of % which is &#37 to stop the VBScript run-time from spitting it's dummy (but you can use anything even &lt; for < and &gt; for > as has been suggested).

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

    Outputs:

    <%=Count%>