web.config 和 app.config 混淆 [英] web.config and app.config confusion

查看:32
本文介绍了web.config 和 app.config 混淆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个引用 Web 服务的 DLL.

I have a DLL that references a web service.

它放入 app.config 的块是(我已经更改了名称,但您会明白的):

The block it has put into the app.config is (I have changed the names but you'll get the idea):

<applicationSettings>
    <DLLName.My.MySettings>
        <setting name="DLLName_WebReferenceName_ASMXName"
            serializeAs="String">
            <value>http://URL/Filename.asmx</value>
        </setting>
    </DLLName.My.MySettings>
</applicationSettings>

我的网站引用了这个 DLL.

My website references this DLL.

问题是,我要在 web.config 中添加什么来覆盖上述设置(或者,我是否只是将 app.config 放在 BIN 目录中)?

The question is, what do I add to the web.config to override the above setting (alternativly, do I just put the app.config in the BIN directory)?

我需要能够覆盖生产服务器上 Web 服务的 URL,因为它无法访问 app.config 中指定的 URL(这是一个我们不会讨论的不同问题).

I need to be able to override the URL for the webservice on the production server because it can't reach the URL specified in the app.config (that is a different issue we wont go into).

推荐答案

在 configSections 中创建一个名为 applicationSettings 的新 sectionGroup 并将您的 app.config 配置粘贴到 web.config 中,如下所示,然后您可以覆盖您的 app.config 设置.

Create a new sectionGroup in configSections called applicationSettings and paste your app.config configuration into web.config as shown below and then you can override your app.config settings.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
        <sectionGroup name="applicationSettings" 
                type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
            <section name="Playground.ConfigurationOverride.DataAccess.Properties.Settings" 
                    type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" 
                    requirePermission="false" />
        </sectionGroup>
    </configSections>
    <applicationSettings>
        <Playground.ConfigurationOverride.DataAccess.Properties.Settings>
            <setting name="MySetting" serializeAs="String">
                <value>Setting in DataAccess</value>
            </setting>
        </Playground.ConfigurationOverride.DataAccess.Properties.Settings>
    </applicationSettings>
</configuration>

这篇关于web.config 和 app.config 混淆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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