classic asp character encoding
Asked Answered
A

3

7

I'm having a problem with Spanish characters in a classic asp site. A user is able to submit their name/address in a form on an aspx page. The aspx page then does an ajax post to a classic asp page which all it does is stored in our Sql 2008 DB. I can see in the database that the character is not stored correctly. For example the first name looks like Mª where it should be .

When I then read that data and display it in a text box it is still displaying Mª.

things I've tried:

  • <%@ Language=VBScript codepage=65001 %> <% Response.Charset="UTF-8" %>
  • encoding file as UTF-8 (using notepad++)

any other ideas? Do I need to go back into the database and fix the characters first or can this be done when I read the characters and display them?

Atronna answered 22/8, 2012 at 23:40 Comment(5)
Is that code you posted in both the file that is used to receive the form POST as well as the file that contains the originating form? Are you using GET or POST as the form method? What DB engine are you using? Have you read this answer: https://mcmap.net/q/1038840/-classic-asp-how-to-convert-a-utf-8-string-to-ucs-2 ?Cara
the form is on an aspx page and it does an ajax post to a classic asp page that saves the data in the DB. I've checked and this asp page has no encoding information in it.Atronna
I was able to use the code snipit in the post you provided and it appears to be converting the characters correctly for display.Atronna
k so you can fix the corruption that is in the DB but you also need to find the source of the corruption and fix that. The place to start with that is to read each of the questions I posed above and carefully answer each one individually.Cara
hanselman.com/blog/InternationalizationAndClassicASP.aspxHalftimbered
P
3

What you are looking at is UTF-8. It's probably exactly as it should be, and the problem is that the tool you use for the looking is not handling the UTF-8 correctly, either because it cannot, or because it is not configured correctly.

Phrixus answered 23/8, 2012 at 4:10 Comment(5)
the "tool" is an asp page in Firefox, IE or chrome.Atronna
So does the page get interpreted as UTF-8 by the browser?Phrixus
How do I check, and how do I enforce that for other users? I've set the codepage and response charset already.Atronna
At least in Firefox, it will tell you in the Page Properties or similar. Examine the Content-Type: header of the HTTP response; and if you don't have a suitable http-equiv meta tag in your HTML, add one.Phrixus
Well, the tool in this case is a Classic ASP page,,, so should have encoding declarations if data is in UTF-8: Session.CodePage = 65001 Response.charset ="utf-8" Different thing is if the data is encoded in another encoding like Win-1252, then the declarations must be accordingly to that encoding.Sexdecillion
S
12

I had same problem when started using utf-8 on ASP, found that session.CodePage makes the difference. In classic ASP pages do always this first ASP declarations to ensure all page uses UTF-8 for data, forms, asp code, data received or sent.

<%@Language=VBScript CodePage = 65001%>
<%
Session.CodePage = 65001
Response.charset ="utf-8"
Session.LCID     = 1033 'en-US
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
Sexdecillion answered 13/3, 2013 at 17:23 Comment(2)
thanks, that's exactly whet I ended up adding to resolve it, along with needing to clean up the data that was inserted incorrectly.Atronna
Wouldn't it make more sense to just add the session stuff once in Session_OnStart()?Cowpuncher
P
3

What you are looking at is UTF-8. It's probably exactly as it should be, and the problem is that the tool you use for the looking is not handling the UTF-8 correctly, either because it cannot, or because it is not configured correctly.

Phrixus answered 23/8, 2012 at 4:10 Comment(5)
the "tool" is an asp page in Firefox, IE or chrome.Atronna
So does the page get interpreted as UTF-8 by the browser?Phrixus
How do I check, and how do I enforce that for other users? I've set the codepage and response charset already.Atronna
At least in Firefox, it will tell you in the Page Properties or similar. Examine the Content-Type: header of the HTTP response; and if you don't have a suitable http-equiv meta tag in your HTML, add one.Phrixus
Well, the tool in this case is a Classic ASP page,,, so should have encoding declarations if data is in UTF-8: Session.CodePage = 65001 Response.charset ="utf-8" Different thing is if the data is encoded in another encoding like Win-1252, then the declarations must be accordingly to that encoding.Sexdecillion
A
0

Use always Server.HTMLEncode in your pages for every text inside the HTML.

Remember that in ASP the character inside the ASP file is (or may be) the current default in the operating system. For example: Windows-1252 or CP-1252 (code page 1252).

So in constants inside code you shoud write:

text = "M" & Chr(170) 'M + feminine ordinal sign

All source file may contains only ASCII characters.

In all cases, you should use the HTML encoding in this way:

<input type="text" value="<%= Server.HTMLEncode(text & "") %>">

Result:

<input type="text" value="M&#170;">
Ammerman answered 4/6 at 12:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.