In a .net
MVC project we're using serialized (to JSON) classes between requests for persistence. Basically we store serialized userdata within cookies so that we can use it again in later stages and render it on certain places.
One of the items we serialize is the user's location of residence, which in some cases contains a special character like the 'ë' (instead of a normal 'e'). After serializing this character, the cookie contains a sequence that is supposed to represent the character, though when we render the string on the screen it does not format it again the way it is supposed to.
Example:
- Input string: Sint Odiliënberg
- String in cookie: Sint Odiliënberg
- String when rendered: Sint Odili%C3%83%C2%ABnberg
Obviously I need the rendered string to be identical to the input string.
Code we use to serialize (json.net library):
public class ClassWithResidenceProperty {
public string Residence {get;set;}
public string Serialize()
{
return JsonConvert.SerializeObject( this );
}
}
Also, I cannot reproduce this bug when I run the application locally. It makes me think that there might be some culture flag I need to set somewhere. I tried this:
return JsonConvert.SerializeObject( this,
new JsonSerializerSettings()
{
Culture = new CultureInfo("nl-NL")
}
);
(I live in the Netherlands). However, forcing this culture does not change anything on our test environment.
- I'm looking for an idea of what could be causing this issue.
- What I essentially need is the string rendered in the correct format.
Any suggestion or remark is appreciated.