防止百分比字符转换

发布于 2024-11-17 16:29:55 字数 602 浏览 3 评论 0原文

我尝试将 Web 部署工具包与我们的 MVC3 项目一起使用,总体部署工作正常,但我们到数据库的连接字符串的密码包含一个百分号 (%) 字符,后跟两个数字。部署工具包似乎正在将其转换为十六进制字符替换。有没有办法防止这种字符替换并仍然保持连接字符串在开发人员计算机上可用?我尝试将替换内容放入 Web.Debug.Config 文件中,甚至添加 %25 而不仅仅是 %,以尝试让它仅替换 % 字符,并且它仍然替换完整值。

示例:

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

被替换为

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

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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

仅冇旳回忆 2024-11-24 16:29:55

将连接字符串的 pwd 部分设置为:

pwd=abc123%252572

经过多次试验和错误,我发现它确实是双重通过的。第一遍将 %2525 转换为 %25,第二遍将 %25 转换为 %。这就是为什么当您使用 %2572 时,它会生成 r(%72 是 r 的 Unicode 代码)。在我看来,这就像解析器中的一个错误。也许更有知识的人可以给出更好的解释。

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.

鸢与 2024-11-24 16:29:55

我遇到了完全相同的问题(当然密码不同)。

为了保持数据库的连接字符串在开发人员计算机上正常工作,我修改了发布设置以使用“不同的”连接字符串。

对于你的例子:
web.config 将包含:

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

在发布设置下右键单击项目,选择发布...,转到设置->数据库。对于数据库 MyDB,输入

 server=Server1;uid=user1;pwd=abc123%72;database=Database1;

这允许我的开发人员计算机保留与数据库的连接,并且主机可以通过直接发布或通过 teamcity 自动使用正确的连接字符串。

I've run into the exact same issue (with a different password of course).

To keep the connection string to the database working on the developer machines i've modified the publish settings to use a 'different' connections string.

For your example:
web.config would contain:

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

Under the publish settings right-click project, select publish..., go to settings->databases. For the database MyDB, enter

 server=Server1;uid=user1;pwd=abc123%72;database=Database1;

This allowed my developer machine to retain it's connection to the database and the host machine to automatically use the correct connection string both by publishing directly or through teamcity.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文