asp.net-mvccharacter-encodingutf-7

Adding "charset" to all ASP.NET MVC HTTP responses


Is there an easy way to specify all "normal" views is an ASP.NET MVC app are to have charset=utf-8 appended to the Content-Type? View() lacks an override that allows you to specify the Content-Type, and ActionResult and friends don't seem to expose anything, either. The motivation is obviously to work around Internet Explorer guessing the "correct" encoding type, which I in turn want to do to avoid UTF-7 XSS attacks.


Solution

  • Maybe this in your web.config will do the magic?

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