一个aspx页面有utf-8编码

时间:2015-10-22 14:37:50

标签: c# asp.net vb.net utf-8

如何更改一个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" 

不起作用。

2 个答案:

答案 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