(ASP.NET) 您可以对 web.config 键/值执行 String.Format 吗?

发布于 2024-07-27 22:06:56 字数 319 浏览 8 评论 0原文

这可能是一个可怕的问题,但我不确定为什么它不允许我这样做。

我有一个需要存储在 Web.config 中的 URL,其中包含从网页中提取的动态参数。

所以我想存储:

        <add key="TestURL" 
value="https://test/subscribe?msisdn={0}&code=1&pass=2"/>

它不允许我这样做。 在 {0} 之后,它在“&”处出错。

谁能让我知道我在这里做错了什么? 我需要逃避这个角色吗?

This might be a god awful question but I'm not sure why it won't let me do this.

I have a URL I need to store in Web.config, which has a dynamic parameter pulled from the web page.

So I want to store:

        <add key="TestURL" 
value="https://test/subscribe?msisdn={0}&code=1&pass=2"/>

It doesn't let me do this. After the {0} it errors at the "&".

Can anyone let me know what I'm doing wrong here? Do I need to escape the character?

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

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

发布评论

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

评论(2

请叫√我孤独 2024-08-03 22:06:56

配置文件是 XML,因此需要对 XML 实体进行转义。 问题不在于您在格式化时使用的 {0},而在于 & 必须转义为

&

Config files are XML, and as such, require XML entities to be escaped. The problem isn't your {0} for use in formatting, it's the & that must be escaped as

&
ヤ经典坏疍 2024-08-03 22:06:56

试试这个,

<add key="TestURL" value="https://test/subscribe?msisdn={0}&code=1&pass=2"/>

注意转义的 & 符号。

Try this instead,

<add key="TestURL" value="https://test/subscribe?msisdn={0}&code=1&pass=2"/>

Notice the escaped ampersands.

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