使用查询字符串解析AppSettings值时出错 [英] Error parsing AppSettings value with a query string

查看:264
本文介绍了使用查询字符串解析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:


解析EntityName时出现错误

An error occurred while parsing EntityName

为什么会这样,如何在App.config中包含这样的URL?

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

推荐答案

& 替换为& amp; amp; (将其转义):

Replace & with &amp; (escape it):

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

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

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

请参阅我在哪里获取XML文档转义字符的列表?

这篇关于使用查询字符串解析AppSettings值时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆