C# 如何设置IIS网站的默认编码?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9781157/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to set IIS website's default encoding?
提问by u1230329
My website is a combination of classic ASP and ASP.NET
我的网站是经典的 ASP 和 ASP.NET 的结合
My pages' default encoding is currently ISO-8859-1.
我的页面的默认编码目前是ISO-8859-1。
Even if there's no <meta>tag, the response page will be encoded ISO-8859-1.
即使没有<meta>标签,响应页面也会被编码为ISO-8859-1。
How to change it to UTF-8?
如何将其更改为UTF-8?
采纳答案by FlavorScape
You could try adding the header to the HTTP Response Headers list for that site. If none is specified, it will be delivered in whatever the user agent requests, which is likely why you're seeing the ISO-8859-1
您可以尝试将标头添加到该站点的 HTTP 响应标头列表中。如果没有指定,它将在用户代理请求的任何内容中交付,这可能是您看到 ISO-8859-1 的原因
"Properties" => "HTTP Headers" => "File Types..." => "New Type...". Put in the extension you want to map, separately for each extension; IIS users will probably want to map .htm, .html,... Then, for Content type, add "text/html;charset=utf-8" (without the quotes; substitute your desired charset for utf-8;
“属性”=>“HTTP 标头”=>“文件类型...”=>“新类型...”。放入你要映射的扩展名,分别为每个扩展名;IIS 用户可能想要映射 .htm、.html、... 然后,对于内容类型,添加“text/html;charset=utf-8”(不带引号;将所需的字符集替换为 utf-8;
回答by PraveenVenu
The content encoding is set in the Machine.configfile when the .NET Framework is installed. You can edit this file which will affect the response encoding of all ASP.NET sites, or you can override it on a per-site basis using the <globalization>element in each site's Web.configfile.
Machine.config安装 .NET Framework 时,将在文件中设置内容编码。您可以编辑此文件,这将影响所有 ASP.NET 站点的响应编码,或者您可以使用<globalization>每个站点Web.config文件中的元素在每个站点的基础上覆盖它。

