locked
Special character adding for character á RRS feed

  • Question

  • User-595461256 posted

    Hi ,

    Thanks in Advance.

    I am working in a web application. I want to get list of employees who matches with the given employee name. 

    Search is working fine while giving  normal alphabets like (Albert,Jones.. etc.)

    I am not getting any results when search with the names "Luzárraga"  (For example François  , Françoise Lefèvre,Séverinu ,Véronique)

    The problem here is  á character. While debugging I am getting employee name  as "Alberto Luzárraga"  instead of  Alberto Luzárraga ,there are some special character and number.

    My queries are like ,

    What is happening here why  character á sending as á . ?

    How to handle these inputs in jquery or in c# code?

    Please assist me what type of conversion I need to do to get the actual input Alberto Luzárraga?

    Monday, December 3, 2018 9:12 AM

Answers

  • User-821857111 posted

    I am not getting any results when search with the names "Alberto Luzárraga"  (For example François De Bauw , Françoise Lefèvre,Séverin Robillard,Véronique Delaittre)
    This may well depend on your database collation: https://dba.stackexchange.com/questions/190969/ignore-accents-in-where

    While debugging I am getting employee name  as "Alberto Luzárraga"  instead of  Alberto Luzárraga ,there are some special character and number.
    All values are HTMLencoded for display in a Razor View. á is the HTML entity for a lower case a with an acute accent. Check the raw database value to see what has been stored. If it has been stored with á as part of the value, the source of the issue is more likely in how the value is stored initially.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, December 3, 2018 9:53 AM
  • User-821857111 posted

    The HtmlEncode method encodes characters to their HTML entity equivalents. It is usually used for encoding values that you want to render to the browser when you don't intend to output HTML. So it's used in View code. However, Razor automatically HtmlEncodes output, so these days, you rarely need to use it at all.

    I can't actually think of a sensible use-case when it makes sense to encode values submitted via a form for storage in a database. You can't reuse that data outside of a web page. You can't, for example, use it for mailing labels, spreadsheets etc, etc*. And it makes searching very difficult as you have found.

    *Actually, you can, but you have to HtmlDecode every value, and that method is not available to Windows Forms or WPF, for example.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, December 3, 2018 11:50 AM
  • User-595461256 posted

    Hi,

    Thanks for your support.

    Finally, I compared both the application web.config then I found that EncoderType not mentioned in the config

    I just added  encoderType="System.Web.Security.AntiXss.AntiXssEncoder" in the config file then it works.

    Thanks

    Pughal

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 5, 2018 7:29 AM

All replies

  • User-821857111 posted

    I am not getting any results when search with the names "Alberto Luzárraga"  (For example François De Bauw , Françoise Lefèvre,Séverin Robillard,Véronique Delaittre)
    This may well depend on your database collation: https://dba.stackexchange.com/questions/190969/ignore-accents-in-where

    While debugging I am getting employee name  as "Alberto Luzárraga"  instead of  Alberto Luzárraga ,there are some special character and number.
    All values are HTMLencoded for display in a Razor View. á is the HTML entity for a lower case a with an acute accent. Check the raw database value to see what has been stored. If it has been stored with á as part of the value, the source of the issue is more likely in how the value is stored initially.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, December 3, 2018 9:53 AM
  • User-595461256 posted

    Thanks for swift response and helpful. 

    I was debugging  into code I found they are using Server.HtmlEncode(EmployeeName) as you mentioned.

    But, They are using only for this employeename textbox and there are many textbox values which is not htmlencode.

    so,

    What is the purpose of using HtmlEncode and when to use it?

    Will it affect anything if I do HtmlDecode ?

    Thanks

    Pughal

    Monday, December 3, 2018 11:03 AM
  • User-821857111 posted

    The HtmlEncode method encodes characters to their HTML entity equivalents. It is usually used for encoding values that you want to render to the browser when you don't intend to output HTML. So it's used in View code. However, Razor automatically HtmlEncodes output, so these days, you rarely need to use it at all.

    I can't actually think of a sensible use-case when it makes sense to encode values submitted via a form for storage in a database. You can't reuse that data outside of a web page. You can't, for example, use it for mailing labels, spreadsheets etc, etc*. And it makes searching very difficult as you have found.

    *Actually, you can, but you have to HtmlDecode every value, and that method is not available to Windows Forms or WPF, for example.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, December 3, 2018 11:50 AM
  • User-595461256 posted

    Hi ,

    Thanks for Response.

    You are right while doing HtmlEncode some extra character adding for these name (For example François  , Lefèvre,Séverin,Véronique )

    But for the same case I am doing HtmlEncode in another application there is no extra characters adding after HtmlEncode for the above names.

    I checked the DB its all fine. Anyway, I am not storing htmlencode value in the database. I just want get the values for the name entered .In the database name store

    as user inputs(François ,Luzárraga ).

    My query is ,

    Why its inconsistent  and one application its getting exact name ? but both application running in the same cultureinfo.

    Why Server.HtmlEncode not getting exact name ? Instead I am getting like " Alberto Luzárraga" for Luzárraga

    Please help me out.

    Thanks

    Pughal

    Tuesday, December 4, 2018 7:19 AM
  • User-821857111 posted

    Why its inconsistent  and one application its getting exact name ? but both application running in the same cultureinfo.
    I'm not clear what the difference is between the two applications? 

    Tuesday, December 4, 2018 9:14 AM
  • User-595461256 posted

    Hi,

    Thanks for your support.

    Finally, I compared both the application web.config then I found that EncoderType not mentioned in the config

    I just added  encoderType="System.Web.Security.AntiXss.AntiXssEncoder" in the config file then it works.

    Thanks

    Pughal

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 5, 2018 7:29 AM