经典 ASP 和 UTF-8 [英] Classic ASP and UTF-8

查看:21
本文介绍了经典 ASP 和 UTF-8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在更改我的应用程序以使用 utf-8 页面.所以每个ASP页面都有这段代码

I'm changing my application to work with utf-8 pages. So every ASP page has this code

Response.CodePage = 65001 
Response.CharSet = "utf-8"

HTML

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

我在 Visual Studio 2013 中使用编码 UTF-8(签名)65001 保存了所有文档.

I saved all documents in Visual Studio 2013 with encode UTF-8 (without signature) 65001.

当我像这样在 HTML 中编写特殊字符时,这可以正常工作:

This is working fine when I write special characters in HTML like this:

<p>Atenção</p>

但是当我用 VBScript(经典 ASP)编写时,它不起作用并且特殊字符很乱.我可以通过使用编码 UTF-8(with 签名)65001 保存文档 (.asp) 来修复它们.

But when I write in VBScript (classic ASP) it's not working and the special characters are messy. I can fix them by saving the document (.asp) with encode UTF-8 (with signature) 65001.

所以,我的问题是:

  • 我必须在每个页面上使用这种编码(带签名)吗?
  • 我会遇到什么样的问题?

推荐答案

您需要为每个 .asp 文件设置 @Codepage 指令.我们正在使用一个通用的 #include 文件,该文件首先包含在每个页面上,并且前面有以下几行:

You need to set the @Codepage directive for each .asp file. We are using a generic #include file that is included first on every page and has the following lines up front:

<%@Codepage = 65001 %>
<% Option explicit %>
<% Response.Codepage = 65001 %>

查看有关代码页指令的更多信息这里(备注部分).链接的页面是关于 Session.Codepage 如果你想使用内置的 Session 也可能会让你感兴趣.

See more info about the Codepage directive here (Remarks section). The linked page is about Session.Codepage which might also get interesting for you if you want to use the built-in Session.

使用 BOM 保存所有文件不是 IIS 的要求,我们保存所有没有 BOM 的文件都可以正常工作.

Saving all files with BOM is not a requirement for IIS, we have all files saved without BOM working properly.

在使用 ASP 多年后,我的经验是:我们有时会遇到源文件 BOM 潜入生成的输出的问题,这会导致 AJAX/JSON 响应出现问题.补救措施是在写入输出之前使用 Response.Clear.

A note from my experience, after working with ASP for many a year: we had sometimes problems with BOMs of source files sneaking into the generated output, which lead to problems in AJAX/JSON responses. The remedy was to use a Response.Clear before writing output.

这篇关于经典 ASP 和 UTF-8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆