You must Sign In to post a response.
  • Category: .NET

    HttpUtility.HtmlEncode is getting problem when using other language characters

    Hai Guys,
    In my application, I am using HttpUtility.HtmlEncode to encode the special characters. It is working fine when using the English characters or when opening the site in en-US
    But when it comes with other language or if the name is something like 'Hélène Zalkind-Gimenes', in that case, it is displaying 'Hélène Zalkind-Gimenes'.
    Does anyone faced this type of issue earlier in their code.
    Thanks in advance.
  • #763990

    Hai Guys,
    After some struggle, I was able to find the solution of the issue I mentioned above.
    I found-out 2 solutions for this:
    Solution #1:
    1. First of all, we need to make sure that the string is not encoded before. i.e. it is not using HttpUtility.HtmlEncode
    2. If so, then we need to remove it.
    3. Wherever we are displaying the value, we can use the @Html.Raw(yourstring) this will display the string.
    4. MVC version 3 onward, we need not to do the encoding as it is automatically enabled so we don't require to encode. But we need to make sure that this is just to display and not the user entered field. If it is user entered field, then we can use @Html.AttributeEncode to do the encoding so that any html script should not be entered without encoding.
    Solution #2:
    1. Create a method which will take the string.
    2. Read each characters of the string and check if the ASCII value of the character is greater than 127, do not encrypt it. The special characters å, ä, ö, è, é, ç, ü will have ASCII value greater than 127.
    Hope it will be helpful for other.

    Pawan Awasthi(DNS MVM)
    +91 8123489140 (whatsApp), +60 14365 1476(Malaysia)

  • #764110
    Hi Pawan,

    Very important information for me as well as to all others, thank you very much for sharing this. :)

    Shashikant Gurav[Programmer II]

  • #764140
    Hi Pawan.

    Thanks for providing the solution for the problem you faced.
    It will be helpful for the people who face same kind of issue.

    Sridhar Thota.
    Editor: DNS Forum.

  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.