ASP页面编码问题

1.作用


MSDN:
Setting @CODEPAGE explicitly affects literal strings in a single response.
Response.CodePage affects dynamic strings in a single response,
and Session.CodePage affects dynamic strings in all responses in a session.


@CODEPAGE作用于所有静态的字符串,比如某文件中的Const myBlog="我的博客"
Response.CodePage和Session.CodePage作用于所有动态输出的字符串,比如<%=myBlog%>


2.范围

MSDN:

If Response.CodePage is not explicitly set in a page, it is implicitly set by Session.CodePage,
if sessions are enabled. If sessions are not enabled, Response.CodePage is set by @CodePage,
if @CodePage is present in the page. If there is no @CodePage in the page,
Response.CodePage is set by the AspCodePage metabase property.
If the AspCodePage metabase property is not set, or set to 0, Response.CodePage is set by the system ANSI code page.


Response.CodePage的作用范围是a single response
Session.CodePage的作用范围是all responses in a session

在Session.CodePage被任何程序声明的时候,如果Response.CodePage没有声明,则Response.CodePage会被Session.CodePage赋值。
如果Session.CodePage没有被任何程序声明的时候, 如果CodePage已声明,则Response.CodePage会被CodePage赋值,
最后的页面动态内容部分按照Response.CodePage的值解释。


3.乱码的原因

MSDN:

If you set Response.CodePage or Session.CodePage explicitly, do so before sending non-literal strings to the client.
If you use literal and non-literal strings in the same page, make sure the code page of @CODEPAGE matches
the code page of Response.CodePage, or the literal strings are encoded differently from the non-literal strings and display incorrectly.

如果Response.CodePage和@CODEPAGE不一样的话会产生乱码。


4.解决方法

<%@ CODEPAGE=65001 %>
<% Response.CodePage=65001%>
<% Response.Charset="UTF-8" %>


5.以上方法可以解决正常页面的乱码问题,但出错提示页仍会有乱码

解决方法为找到相应的出错页修改其编码,默认编码为gb2312

如找到C:\WINDOWS\Help\iisHelp\common\500-100.asp 将其编码改为utf-8,即可正常显示。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值