How to set encoding to utf-8 on a IIS web.config file?

22,604

You need to set the responseEncoding attribute of the globalization element.

<globalization
    responseEncoding="utf-8"
/>

In context:

<configuration>
    <system.web>
        <globalization 
           requestEncoding="utf-8"
           responseEncoding="utf-8"
        />
    </system.web>
</configuration>
Share:
22,604
omega
Author by

omega

Updated on July 09, 2022

Comments

  • omega
    omega almost 2 years

    I have this

    <?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>
    

    How do I set the encoding to utf-8 for files sent to client. Actually There can be other types of files sent to clients like js,css,images. But I have aspx pages, that I want to set text/html; charset=utf-8" content-type to. How can I add this to this web.config code?

    Thanks

  • omega
    omega almost 7 years
    where do I insert that into the web.config, and if I edit the web.config do I need to restart the IIS server?
  • John Wu
    John Wu almost 7 years
    Follow the link. The page has an example showing the element in context. When you edit web.config, IIS will automatically recycle the app pool; you won't need to perform an iisreset manually.