(ASP.NET) 您可以对 web.config 键/值执行 String.Format 吗?
这可能是一个可怕的问题,但我不确定为什么它不允许我这样做。
我有一个需要存储在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
配置文件是 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
试试这个,
注意转义的 & 符号。
Try this instead,
Notice the escaped ampersands.