Special characters not returned correctly

时间:2017-07-10 15:17:34

标签: .net asp.net-mvc localization internationalization

I have the following German phrase in a view of my .Net MVC application:

auf der Straße

but when I look at the source that is returned

 auf der Straße 

I can see that it doesn't match what is in the view. I have set the Thread's UI culture to 'de-DE' and the CurrentUICulture to 'de-DE'

 Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("de-DE");
 Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("de-DE");

In my web.config file, I've set the request and response encoding to utf-8:

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

Anything else I can check to figure out how to return the text that is in the view and not something else?

1 个答案:

答案 0 :(得分:1)

原来,你需要将fileEncoding设置为UTF-8,否则从服务器发送的文本不正确。

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