Using Non-usascii Literal Strings in Classic ASP

To use literal strings with non-US-ASCII characters (such as é, ü, ñ, ç, etc.) in Classic ASP, you need to ensure that:

  1. The .asp source file is saved in UTF-8 *without* a BOM (byte order mark), if possible.
  2. The code page used by the server is set to 65001 (UTF-8).
  3. The HTML output tells the browser to expect UTF-8.
  4. The literal strings in the ASP code are interpreted as UTF-8.

1. Save the .asp file as UTF-8

Use a text editor (e.g., Notepad++, VS Code) to save your .asp file with UTF-8 encoding:

  • In Notepad++: Encoding → Convert to UTF-8 (without BOM)
  • In VS Code: Bottom bar → Click encoding → Save with encoding → UTF-8

> Important: Saving with BOM can cause issues in Classic ASP (especially with headers), so UTF-8 without BOM is safest.


2. Set @CodePage to 65001 (UTF-8)

Put this at the top of your .asp file:

<%@ CodePage=65001 %>

This tells Classic ASP to interpret literal strings in the file as UTF-8.


3. Set Response.CodePage and Response.Charset

These control the output encoding of the HTML to the browser:

<%
Response.CodePage = 65001
Response.Charset = "utf-8"
%>

This ensures any strings you output are encoded as UTF-8, and that the Content-Type HTTP header tells the browser to expect UTF-8.


4. Set the HTML META tag

This informs the browser explicitly, in the HTML, to use UTF-8:

<meta charset="utf-8">

Or, for compatibility with older HTML versions:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

5. Example .asp file using literal UTF-8 strings

<%@ Language="VBScript" CodePage=65001 %>
<%
Response.CodePage = 65001
Response.Charset = "utf-8"
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>UTF-8 Test</title>
</head>
<body>
<%
Dim greeting
greeting = "Olá, Señor José! Ça va? Grüß Gott!"
Response.Write "<p>" & greeting & "</p>"
%>
</body>
</html>

Summary

Element Purpose Value/Setting
File encoding Interprets literals correctly UTF-8 without BOM
"<%@ CodePage=65001 %>" Source string interpretation UTF-8
"Response.CodePage" Sets encoding for output 65001 (UTF-8)
"Response.Charset" Sets HTTP header "utf-8"
"<meta charset>" Sets browser HTML charset "utf-8"

When all of these are set properly, non-ASCII characters will display correctly in Classic ASP.

Chilkat Articles