我想在我的web.config中定义一个变量,我可以在我的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文件(实际上是由温莎城堡和一个自定义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>
即 - 以m访问变量从我的web.config文件的其他部分输入y <appSettings>
。
两个配置文件都在同一个目录下吗?请记住,web.config文件是分层文件,因此在根文件web.config中定义的appsettings也可以在子文件夹中的web.config文件中使用。但是,这可能不符合您的要求。 – Manfred 2010-08-05 09:45:58
@John,对不起,我错过了一些关键信息,现在我会更新我的问题。 – 2010-08-05 09:48:23
我删除了我的答案,因为它不再与编辑中提供的额外信息相关。 – 2010-08-05 09:56:10