Search code examples
asp.netasp.net-mvc-3msdeploywebdeploy

Prevent Percent Character Transform


I am attempting to use the Web Deployment Toolkit with our MVC3 project and overall the deployment works fine but our connection string to the database has a password that contains a percent (%) character that is followed by two numbers. The deployment toolkit seems to be transforming this as a Hex character replacement. Is there a way to prevent this character replacement and still keep the connection string usable on developer machines? I tried putting in the replacement in the Web.Debug.Config file and even adding a %25 instead of just the % to try to have it replace just the % character and it still replaces the complete value.

Example:

<connectionStrings>
    <add name="MyDB" connectionString="server=Server1;uid=user1;pwd=abc123%72;database=Database1;"
</connectionStrings>

gets replaced with

<connectionStrings>
    <add name="MyDB" connectionString="server=Server1;uid=user1;pwd=abc123r;database=Database1;"
</connectionStrings>

Solution

  • Set the pwd portion of the connection string to:

    pwd=abc123%252572

    After much trial and error, I discovered that It does a double pass. The first pass will convert %2525 to %25, the second pass converts %25 to %. That is why when you used %2572, it resulted in r (%72 is the Unicode code for r). This seems to me like a bug in the parser. Perhaps someone more knowledgeable can give a better explanation.