如何更改一个aspx页面以进行utf-8编码?
我的web.config包含以下代码:
<system.web>
<globalization
requestEncoding="utf-8"
responseEncoding="utf-8"/>
</system.web>
试过这个:
meta http-equiv="Content-Type" content="text/html; charset=UTF-8"
不起作用。
答案 0 :(得分:11)
试试这个;
<configuration>
<system.web>
<globalization
fileEncoding="utf-8"
requestEncoding="utf-8"
responseEncoding="utf-8"
culture="en-US"
uiCulture="de-DE"
/>
</system.web>
</configuration>
要设置单个页面的编码,请设置RequestEncoding
指令的ResponseEncoding
和@ Page
属性:
<%@ Page RequestEncoding="utf-8" ResponseEncoding="utf-8" %>
或者您可以像这样使用location
:
<location path="home.aspx">
<system.web>
<globalization requestEncoding="utf-8" responseEncoding="utf-8" />
</system.web>
</location>
了解详情:How to: Select an Encoding for ASP.NET Web Page Globalization.
答案 1 :(得分:1)
尝试插入
Response.ContentEncoding = System.Text.Encoding.UTF8;
如果您想动态地执行此操作,请Page_Load
。