使用 VB 和 .Net 1.1 从 web.config 文件获取配置值

发布于 2024-07-04 05:53:37 字数 882 浏览 4 评论 0原文

我有以下网络配置文件。 我在从“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>

I have the following web config file. I am having some difficulty in retrieving the value from the "AppName.DataAccess.ConnectionString" key. I know I could move it to the AppSetting block and get it realtively easily but I do not wnat to duplicate the key (and thereby clutter my already cluttered web.config file). Another DLL (one to which I have no source code) uses this block and since it already exists, why not use it.

I am a C# developer (using .Net 3.5) and this is VB code (using .Net 1.1 no less) so I am already in a strange place (where is my saftey semicolon?). Thanks for your help!!

<?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>

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

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

发布评论

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

评论(1

守不住的情 2024-07-11 05:53:37
<section name="AppNameConfiguration" 
type="AppName.SystemBase.AppNameConfiguration, SystemBase"/>

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

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

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

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

The custom section is supposed to have a class that defines how the various configuration data can be managed, (This is in the Type section). Is this class not available for you to examine?

MSDN has a decent explanation of how to create custom configuration sections in VB that may be helpful to you:

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

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