How to enable unicode characters in web.config for my MVC application?

I wanted to add cool characters to the names and add a cow like this to my web.config.

<add key="SenderName" value="&#x1f3eb; Mr Mooo"/> 

However, when I run the application, I get an exception on this line in my _Layout.cshtml nagging about localization, etc.

 @Styles.Render("~/Content/css") 

I am not sure how to handle this. Apparently MVC hates cows, but what can I do about it?

I tried to execute the proposed syntax according to the standard. I also added UTF-16 at the top of the configuration file.

+5
source share
2 answers

This has nothing to do with Unicode characters and anything related to removing XML.

As stated in the XML standard that you are associated with, XML defines only 5 standard objects:

  • <represents "<";
  • > represents ">";
  • & presents "&";
  • & APOS; presents "'";
  • " presents '' '.

All other objects (e.g. &#x1f3eb; ) are not valid in XML unless you explicitly define them.

However, there is a simple way out of this situation. The problem with this object is that it contains an ampersand that is NOT escaped, which makes it incompatible with XML. You just need to avoid this, and everything is in order with the world.
 <add key="SenderName" value="&amp;#x1f3eb; Mr Mooo"/> 

Now your application will receive the raw string you want: &#x1f3eb; Mr Mooo &#x1f3eb; Mr Mooo , when you extract it from the configuration file, and then you can pass it to the view.

0
source

Try setting the encoding both in the header and in the node configuration for the system.web-set globalization node "fileEncoding" parameter for utf-16.

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

PS Sorry - the last time I typed on my tablet, so it was difficult to write an example.

0
source

Source: https://habr.com/ru/post/1247660/


All Articles