如何在 IIS web.config 文件上将编码设置为 utf-8?



我有这个

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appSettings>
<add key="ContentServer" value="true" />
</appSettings>
<connectionStrings />
<system.web>
<trace enabled="false" requestLimit="25" pageOutput="false" traceMode="SortByTime" localOnly="false" />
<customErrors mode="Off" />
<compilation debug="false" />
<authentication mode="Windows" />
</system.web>
</configuration>

如何将发送到客户端的文件的编码设置为 utf-8。实际上,可以向客户端发送其他类型的文件,例如js,css,images。但是我有 aspx 页面,我想将其设置为text/html; charset=utf-8"内容类型。如何将其添加到此 web.config 代码中?

谢谢

您需要设置全球化元素的responseEncoding属性。

<globalization
responseEncoding="utf-8"
/>

在上下文中:

<configuration>
<system.web>
<globalization 
requestEncoding="utf-8"
responseEncoding="utf-8"
/>
</system.web>
</configuration>

最新更新