Do I need web.config for non-ASCII characters?

Trying to make my first ASP.NET page. Got IIS 5.1 in XP, configured to run .NET 4. Created a new virtual directory and added the .aspx file. When I view the file, non-ASCII characters are corrupted. For example, รผ (U + 00FC) is converted to รƒยผ (U + 00C3 U + 00BC), which is equivalent to I-not-get-this-is-UTF-8.

I tried various ways to use this:

  • I made sure that the .aspx file is really encoded as UTF-8.
  • I set the meta tag:

    <meta charset="UTF-8">

  • I set the virtual directory to handle .aspx as text/html;charset=utf-8under the HTTP headers> File Type in IIS.

  • I added ResponseEncoding="utf-8"in <%@ Page ... %>.
  • I inserted a line in HttpUtility.HtmlEncoded(). Now รผ has been converted to ยผ (U + 00C3 U + 00BC).

Finally, I found two ways to work:

  • Replacing non-ASCII characters with symbolic links such as &#252;This was normal in the 90s, not today.
  • Adding the web.config file to the virtual directory with this content:

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <system.web>
        <globalization fileEncoding="utf-8"/>
      </system.web>
    </configuration>
    

Without a parameter fileEncoding, the ASP.NET parser will read .aspx and corrupt every character without ASCII characters, without trying to infer the encoding of the file. Is this something that you, professionals, have learned to live, or am I missing something? Is the globalization web.config file a way to handle "international" characters on .aspx pages? I donโ€™t remember that I had similar problems with PHP, so I am puzzled why this is due to ASP.NET.

+5
source share
1 answer

, ASCII, . UTF-8, , web.config

<globalization requestEncoding="utf-8" responseEncoding="utf-8"  fileEncoding="utf-8" />

, web.config ASP.NET. , asp.net {drive:}\WINDOWS\Microsoft.NET\Framework\{version}\CONFIG\, web.config . . UTF-8 .

, 3 :

  • .
  • requestEncoding = "utf-8"
  • responseEncoding = "utf-8"
+3

All Articles