使用查询字符串解析 AppSettings 值时出错

发布于 2024-11-14 23:54:49 字数 424 浏览 3 评论 0原文

web.config 的 AppSettings 中,我有这样的内容:

<appSettings>
    <add key="ExternalSystemUrl" value="http://example.com/page.aspx?id={0}&action=eat&object=bacon" />
</appSettings>

但是,似乎当 AppSettings 值中包含与号 (&) 时,ASP.NET抛出以下错误:

解析 EntityName 时发生错误

为什么会发生这种情况?如何在 App.config 中包含这样的 URL?

In my AppSettings in web.config, I have something like this:

<appSettings>
    <add key="ExternalSystemUrl" value="http://example.com/page.aspx?id={0}&action=eat&object=bacon" />
</appSettings>

However, it seems that when an ampersand (&) is included in an AppSettings value, ASP.NET throws the following error:

An error occurred while parsing EntityName

Why does this happen, and how can I include URLs like this in App.config?

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

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

发布评论

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

评论(3

小草泠泠 2024-11-21 23:54:49

& 替换为 &(转义):

<add
    key="ExternalSystemUrl"
    value="http://example.com/page.aspx?id={0}&action=eat&object=bacon" />

这是任何有效 XML 文件的常见要求。

请参阅 在哪里可以获得以下列表XML 文档转义字符?

Replace & with & (escape it):

<add
    key="ExternalSystemUrl"
    value="http://example.com/page.aspx?id={0}&action=eat&object=bacon" />

That's the common requirement for any valid XML file.

See Where can I get a list of the XML document escape characters?

无所谓啦 2024-11-21 23:54:49

您可以尝试使用 & 代替。

You can Try using & instead.

才能让你更想念 2024-11-21 23:54:49

在 XML 中,& 符号告诉解析器“紧跟在该 & 符号后面的数据是需要翻译的实体”。如果紧随其后的数据不是有效的 XML 实体,则会出现此错误。如果可能,请在 XML 中使用 & 作为 & 符号。

In XML an ampersand tells the parser "the data immediately following this ampersand is an entity which needs to be translated." If the data immediately following is not a valid XML entity, then you get this error. If possible, use & for your ampersand within the XML.

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