【问题标题】:Reading AppSettings value from web.config从 web.config 读取 AppSettings 值
【发布时间】:2011-08-24 08:24:43
【问题描述】:

这是我在 web.config 中的 appSettings:

<appSettings>
  <add key="**Subdomain**" value="england" />
</appSettings>

在同一个 web.config 中,我想读取这个值:

<errorLog applicationName="**Subdomain**" />

有没有办法通过类似的方式实现这一点: ?

【问题讨论】:

  • 您尝试使用System.Configuration.ConfigurationManager.GetSection("sectionpath/section") 吗?

标签: asp.net web-config


【解决方案1】:

为什么不尝试使用“england”作为 applicationName 属性的值呢?我认为在 web.config 文件中包含 appSettings 的目的是允许在运行时更改代码文件中的设置。但是,您正在使用 appSettings 更改在运行时已经可以更改的值。另外,不为此目的使用 appSettings 字典将降低配置文件的复杂性。

【讨论】:

    【解决方案2】:

    由于 web.config 是一个 XML 文件,您可以使用如下代码来访问它:

    http://patelshailesh.com/index.php/update-web-config-programmatically

    如果您还有其他问题,请询问。

    【讨论】:

    • @user675353: 所以你需要在 .aspx 中的某处插入一个带有类似 的标签的值?
    猜你喜欢
    • 2017-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-11
    • 1970-01-01
    • 1970-01-01
    • 2012-10-06
    • 2015-05-11
    相关资源
    最近更新 更多