asp.net - 在 web.config 中使用 web.config 变量

标签 asp.net web-config

我想在我的 web.config 中定义一个变量,我可以在我的 web.config 文件(和其他配置文件)中的多个位置使用它。通过示例可能更容易解释......

web.config

<?xml version="1.0"?>
<configuration>
    <appSettings>
        <add key="AuthServiceEndPoint" value="any_old_name_i_like"/>
    </appSettings>
    <system.web>

    ...

    <system.serviceModel>
        <client>
            <endpoint
                address="net.tcp://localhost/AuthService"
                binding="netTcpBinding"
                contract="MyServices.Contracts.IAuthService"
                name="#{AppSettings.AuthServiceEndPoint}"
                bindingConfiguration="netTcpBindingConfig"
            />

        </client>
    </system.serviceModel>
</configuration>

Windsor.config
<?xml version="1.0" encoding="utf-8" ?>
<castle>
    <components>

        ...

        <component
            id="AuthProvider"
            service="MyServices.Client.IAuthProvider, MyServices.Client"
            type="MyServices.Client.AuthProvider, MyServices.Client"
            lifestyle="transient">
            <parameters>
                <endpoint>#{AppSettings.AuthServiceEndPoint}</endpoint>
            </parameters>
        </component>

    </components>
</castle>

这可能吗?

编辑 (更多信息)

我已经能够从我的 windsor.config 文件(实际上是由城堡 windsor 和自定义 XmlInterpreter 处理的)访问 AppSettings 的能力。

真正的问题是我可以在我的 web.config 中做到这一点吗?
<?xml version="1.0"?>
<configuration>
    <appSettings>
        <add key="AuthServiceEndPoint" value="any_old_name_i_like"/>
    </appSettings>
    <system.web>

    ...

    <system.serviceModel>
        <client>
            <endpoint
                address="net.tcp://localhost/AuthService"
                binding="netTcpBinding"
                contract="MyServices.Contracts.IAuthService"
                name="#{AppSettings.AuthServiceEndPoint}"
                bindingConfiguration="netTcpBindingConfig"
            />

        </client>
    </system.serviceModel>
</configuration>

即 - 我的 <appSettings> 中的访问变量来自我的 web.config 文件的其他部分。

最佳答案

在我的脑海里,我想知道你是否可以用 T4 做到这一点?我在想,也许您可​​以定义一个模板来解析 Web-Template.config 并输出 Web.config?当然,这只适用于单个文件。

关于asp.net - 在 web.config 中使用 web.config 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3413457/

相关文章:

c# - 用于使用参数打开 SSRS 报告新窗口的 ASP 按钮

asp.net - 页面停留超过 20 分钟时 View 状态 MAC 验证失败

asp.net - 以下部分已定义,但尚未为布局页面渲染 "~/Views/Shared/_Layout.cshtml": "Scripts"

winforms - 如何编辑外部 web.config 文件?

asp.net-core - 什么是最好的... ASP.NET Core 模块 processPath 到 .exe 或 .dll

c# - 使用 ASP.NET、C# 和身份验证的简单反向代理

asp.net-mvc - 对于 MVC 应用程序来说,web.config 中的 <customErrors> 去哪里了?

iis - 使用 Web.Config 将目录重定向到子域

php - 从iis服务器的子文件夹中执行Php(MVC)项目

c# - 从 Gridview 的 BoundField 访问数据