ASP.NET将字符编码更改为windows-1252

时间:2012-09-15 09:19:32

标签: asp.net unicode azure character-encoding

我有以下标记:

    <head id="Head1" runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>



    <asp:ContentPlaceHolder ID="TitleContent" runat="server" />
    </title>
    <asp:ContentPlaceHolder ID="HeaderContent" runat="server" />
    <link href="~/Content/Site.css" rel="stylesheet" type="text/css" />
    <link href="~/PublicPages/LogIn.css" rel="Stylesheet" type="text/css" />

    </head>
    <body>
    <form id="form1" runat="server">

    <div class="page">
        <div id="header">
    .....

和这个web.config

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
     <configSections>


    </configSections>
    <system.web>
    <machineKey validation="SHA1" />
    <globalization
      fileEncoding="utf-8"
      requestEncoding="utf-8"
      responseEncoding="utf-8"
      culture="en-US"
      uiCulture="de-DE"
    />

在回发时,我在firefox中收到此错误 未声明HTML文档的字符编码。如果文档包含US-ASCII范围之外的字符,则文档将在某些浏览器配置中使用乱码文本进行渲染。必须在文档或传输协议中声明页面的字符编码 和一个空白页

检查IE中的来源,我看到了:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=windows-1252" http-equiv=Content-Type></HEAD>
<BODY></BODY></HTML>

那么如何阻止asp.net返回带有windows-1252字符集的页面?

1 个答案:

答案 0 :(得分:0)

可能需要检查一些事项。您是否碰巧直接或间接地在您的网页中加载了JavaScript资源?

如果您从磁盘加载的资源文件在其他ASP.NET页面上未进行UTF-8编码,则它们可以呈现为其默认编码。检查是否有任何资源文件仍然使用VS编码Windows 1252作为JavaScript文件。将所有资源文件保存为utf-8类型应将设置更改为utf-8。

要确保所有ASP.NET页面对每个嵌入资源都具有utf-8编码,您可以在每个ASP.NET页面中添加以下内容:

response.codepage = 65001
response.charset = "utf-8"

也可以使用“ firefox -safe-mode ”在没有任何插件的安全模式下启动FireFox,看看是否会改变行为。