我有以下网络配置文件。我在从“AppName.DataAccess.ConnectionString”键检索值时遇到一些困难。我知道我可以将它移动到 AppSetting 块并非常轻松地获取它,但我不想复制密钥(从而使我已经很混乱的 web.config 文件变得混乱)。另一个 DLL(我没有源代码的 DLL)使用这个块,既然它已经存在,为什么不使用它呢?

我是一名 C# 开发人员(使用 .Net 3.5),这是 VB 代码(同样使用 .Net 1.1),所以我已经处于一个奇怪的地方(我的安全分号在哪里?)。感谢您的帮助!!

<?xml version="1.0"?>
<configuration>
    <configSections>
        <section name="AppNameConfiguration" type="AppName.SystemBase.AppNameConfiguration, SystemBase"/>
    </configSections>
    <AppNameConfiguration>
        <add key="AppName.DataAccess.ConnectionString" value="(Deleted to protect guilty)" />
    </AppNameConfiguration>
    <appSettings>
        ...other key info deleted for brevity...
    </appSettings>
    <system.web>
     ...
     </system.web>
</configuration>
有帮助吗?

解决方案

<section name="AppNameConfiguration" 
type="AppName.SystemBase.AppNameConfiguration, SystemBase"/>

自定义部分应该有一个类,定义如何管理各种配置数据(这在类型部分中)。这门课你不可以考吗?

MSDN 对如何在 VB 中创建自定义配置部分有一个很好的解释,可能对您有帮助:

http://msdn.microsoft.com/en-us/library/2tw134k3.aspx

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top