asp.net - web.config 和 app.config 混淆

标签 asp.net web-services web-config app-config

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

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

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

我的网站引用了这个 DLL。

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

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

最佳答案

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

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

关于asp.net - web.config 和 app.config 混淆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1503247/

相关文章:

c# - 如何在我的 VB.net 应用程序中处理来自 c# Web 服务的区分大小写的类和方法

java - 使用 Play Framework 1.2.5 访问 Web 服务

c# - 从 Azure 中的 SOAP Web 服务检索列表时出现 TargetInitationException

c# - 是否可以使用 ASP.Net Web 配置应用程序设置值作为编译常量?

c# - 与 const 字段相比,在 web.config 中存储值是否有性能损失?

c# - 查询中的“条件是预期的”

ASP.Net MVC 授权操作过滤器

azure - 无法从 Azure 获取 SVG 服务

c# - HTML 被添加到下载文件作为响应

c# - 如何获取收件箱文件夹实例?