3

I have a website written by asp with SQL server 2000. It's good in IIS 5 (on Windows Server 2000 system), all of Vietnamese characters (using unicode utf-8) are show correctly. But when I deploy my web on an IIS 7 web server (Windows Server 2008), database connection still connect to database before. But Vietnamese characters doesn't show correctly. SQL server using SQL_Latin1_General_CP1_CI_AS collation. What should I do to resolve my problems? Thanks for any suggestions.

Kingzing
  • 163
  • 2
  • 8
  • Hanselman has written some really useful things about classic asp and utf-8: http://www.hanselman.com/blog/InternationalizationAndClassicASP.aspx Furthermore Spolsky has written this one which is a must read: http://www.joelonsoftware.com/articles/Unicode.html – ulluoink Mar 13 '14 at 06:32
  • @ulluoink: Thanks for your reply, but my trouble is that website is my customer's, not mine. And they developed it for 6 years ago, not now, all of data have saved into SQL Server. I need a solutions to display saved data in IIS 7. – Kingzing Mar 13 '14 at 12:35
  • Can you edit the asp pages or not? - `Response.CodePage = 65001` as described on the Hanselman blog is usually the key to fixing Character encoding issues in Classic ASP – John Mar 13 '14 at 14:32
  • The source ASP pages will also need to be saved as `UTF-8` not `ASCII` and don't forget the `<% @CodePage="65001" %>` processing instruction at the top of your ASP page. – user692942 Mar 14 '14 at 09:53
  • Honestly this questions is asked over and over on this site just look... [All you need to know to support UTF-8 in Classic ASP](http://stackoverflow.com/a/21914278/692942) There is so much mismatched misunderstood information when it comes to internationalisation in Classic ASP. – user692942 Mar 16 '14 at 13:06

1 Answers1

0

Here are the techniques I use to ensure UTF8 output from classic ASP on 2008.

Before you output any HTML, include the following in your ASP. I place this right after my initial Option Explicit and Response.Buffer:

<%
Session.CodePage = 65001 ' UTF8
Session.LCID     = 1066  ' assuming your LCID will be 1066 = Vietnam. Mine is 1033.
Response.CharSet = "UTF-8"
%>

For the HTML part, assuming you've got an older site so it's probably XHTML, start with this before the doctype declaration:

<?xml version="1.0" encoding="UTF-8"?>

Inside the HTML head tag, include this:

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

Also, all of your ASP/HTML pages should be saved with an editor that lets you save them with UTF8 encoding vs ANSI encoding.

On the db side, remember to use nchar, nvarchar, ntext, etc.

Neil Cresswell
  • 1,145
  • 8
  • 20
  • You could also use Response.AddHeader "Content-Type", "text/html;charset=UTF-8" inside your ASP but from my understanding, the Response.CharSet setting should have you covered. – Neil Cresswell Mar 15 '14 at 23:33
  • You're right @Neil, in fact there is no need for the meta html tags (especially the MS specific ones...geez) or `Session.LCID` either just use `Response.CodePage = 65001` (or session equivalent) and `Response.Charset = "UTF-8"` amazing how many make this mistake. – user692942 Mar 16 '14 at 13:00
  • Thanks for confirming Lankymart and the very useful feedback. Appreciated. :) I needed MS.LOCALE at some point years ago so kept it in my list. Probably left over from the dark ages of earlier versions of IE. I expect most sites are post IE6 so very good point there. Should take that out. Re "extra" HTML tags, it's worth listing them still IMHO for the sake of consistency since you sometimes see "pure HTML" pages not using any ASP at all mixed in, particularly on legacy sites. – Neil Cresswell Mar 16 '14 at 20:53
  • That is a worthy point, if you have static HTML pages then yes by all means include meta tags. – user692942 Mar 17 '14 at 09:30
  • Thank you, Neil Cresswell. I'll try and feedback. Thanks again. – Kingzing Apr 23 '14 at 06:54
  • Would appreciate that. Thanks. – Neil Cresswell Apr 24 '14 at 17:39