本文介绍了使用查询字符串解析AppSettings值时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的AppSettings在web.config中,我有这样的东西:
In my AppSettings in web.config, I have something like this:
<appSettings>
<add key="ExternalSystemUrl" value="http://domain.com/page.aspx?id={0}&action=eat&object=bacon" />
</appSettings>
然而,似乎当一个&符号(&
)包含在AppSettings值中,ASP.NET会抛出以下错误:
However, it seems that when an ampersand (&
) is included in an AppSettings value, ASP.NET throws the following error:
为什么会这样,如何在App.config中包含这样的URL?
Why does this happen, and how can I include URLs like this in App.config?
推荐答案
将&
替换为& amp; amp;
(将其转义):
Replace &
with &
(escape it):
<add
key="ExternalSystemUrl"
value="http://domain.com/page.aspx?id={0}&action=eat&object=bacon" />
这是任何有效XML文件的常见要求。
That's the common requirement for any valid XML file.
请参阅
这篇关于使用查询字符串解析AppSettings值时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!