如何在ASP.NET Web应用程序中打开SectionGroup? [英] How to open a SectionGroup in an ASP.NET web application?

查看:96
本文介绍了如何在ASP.NET Web应用程序中打开SectionGroup?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个集成测试(在NUnit中执行)上托管的小型ASP.NET Web应用程序.我的产品代码通常可以从web.config或app.config文件中找到配置数据,但是由于某些原因,在托管ASP.NET时,执行以下第一个命令时似乎会收到 ArgumentException :/p>

I have a small ASP.NET web application hosted in an integration test (executing within NUnit). My product code can usually find configuration data from the web.config or app.config file, but for some reason when hosting ASP.NET I seem to get an ArgumentException when executing the first of these commands:

var configuration = ConfigurationManager.OpenExeConfiguration(null);
return configuration.GetSectionGroup(SectionGroupName);

不在独立exe程序中运行时必须指定exePath.

exePath must be specified when not running inside a stand alone exe.

我不知道该放在哪里.我的产品没有明智的exePath可以作为参数传递给此方法,因为它通常在Web服务器中运行.另外,通常可以使用以下命令打开普通节(不是SectionGroups):

I don't know what to put here. There isn't a sensible exePath for my product to ever pass into this method as a parameter as it usually runs within a web server. Also, ordinary Sections (not SectionGroups) can typically be opened using:

ConfigurationManager.GetSection(SectionName)

即使在单元测试中,此方法也可以正常工作,其中以某种方式神奇地读取了App.config文件.那就是我在阅读SectionGroups时想要的.

even within unit tests this works, where an App.config file somehow magically gets read. That's what I'd like when reading SectionGroups.

有什么想法吗?

推荐答案

System.Configuration.Configuration config =
    ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
return config.GetSectionGroup(SectionGroupName);

应该在asp.net中工作.

should work in asp.net.

这篇关于如何在ASP.NET Web应用程序中打开SectionGroup?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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