Escape quote in web.config connection string

后端 未结 5 1750
梦谈多话
梦谈多话 2020-11-30 02:13

I have a connection string in my web config:



        
5条回答
  •  余生分开走
    2020-11-30 02:34

    connectionString="Server=dbsrv;User ID=myDbUser;Password=somepass"word"
    

    Since the web.config is XML, you need to escape the five special characters:

    & -> & ampersand, U+0026
    < -> < left angle bracket, less-than sign, U+003C
    > -> > right angle bracket, greater-than sign, U+003E
    " -> " quotation mark, U+0022
    ' -> ' apostrophe, U+0027

    + is not a problem, I suppose.


    Duc Filan adds: You should also wrap your password with single quote ':

    connectionString="Server=dbsrv;User ID=myDbUser;Password='somepass"word'"
    

提交回复
热议问题