尝试从 Windows 应用程序读取 web.config 时出现问题

发布于 2024-07-29 22:35:59 字数 668 浏览 3 评论 0原文

我正在编写一个 WPF 应用程序来帮助不懂 XML 的客户在 Web 服务器上设置配置文件。 web.config 就是这些文件之一。 我定义了自定义部分,但我已将它们注释掉,直到我掌握了基础知识。

在 web.config 中,我有这样的:

  <appSettings>
    <add key="buffer" value="65536"/>
    <add key="updateInterval" value=""/>
  </appSettings>

这是我如何读取 web.config 的片段(我已经确认 web.config 存在于 AppPath 中):

var vdm = new VirtualDirectoryMapping(AppPath, true);
var wcfm = new WebConfigurationFileMap();
wcfm.VirtualDirectories.Add("/", vdm);
WebConfigurationManager.OpenMappedWebConfiguration(wcfm, "/");

但是,WebConfigurationManager.AppSettings["buffer"] 返回 null。 有任何想法吗?

I'm writing a WPF application to help non-XML-savvy customers set up configuration files on a web server. web.config is one of these files. I have custom sections defined, but I've commented them out until I get the basics working.

In web.config, I have this:

  <appSettings>
    <add key="buffer" value="65536"/>
    <add key="updateInterval" value=""/>
  </appSettings>

Here's a snippet of how I'm reading web.config (I have already confirmed that web.config exists inside AppPath):

var vdm = new VirtualDirectoryMapping(AppPath, true);
var wcfm = new WebConfigurationFileMap();
wcfm.VirtualDirectories.Add("/", vdm);
WebConfigurationManager.OpenMappedWebConfiguration(wcfm, "/");

However, WebConfigurationManager.AppSettings["buffer"] returns null. Any ideas?

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

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

发布评论

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

评论(1

浅忆流年 2024-08-05 22:35:59

呵呵。 现在是星期一早上。 :-)

var config = WebConfigurationManager.OpenMappedWebConfiguration(wcfm, "/");
config.AppSettings["buffer"];

有效。

Duhhhh. It's Monday morning. :-)

var config = WebConfigurationManager.OpenMappedWebConfiguration(wcfm, "/");
config.AppSettings["buffer"];

works.

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