[英]How can I configure a TransportSecurityBindingElement for a CustomBinding within a web.config?
I have the following (reduced) code that I'd like to configure through a web.config 我有以下(简化的)代码,我想通过web.config进行配置
var security = new TransportSecurityBindingElement();
security.EndpointSupportingTokenParameters.SignedEncrypted.Add(new UserNameSecurityTokenParameters());
var binding = new CustomBinding(security);
Is it possible to configure this custom binding using the web config? 是否可以使用Web配置来配置此自定义绑定? If it is possible how could I configure the endpoint supporting token parameters?
如果可能,如何配置支持令牌参数的端点? I've tried The following config, however it does not validate against DotNetConfig.xsd:
我已经尝试了以下配置,但是它无法针对DotNetConfig.xsd进行验证:
<system.serviceModel>
<bindings>
<customBinding>
<binding name="SomeBinding" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00">
<transportSecurity> <!-- Fails validation -->
<!-- How do I configure the EndpointSupportingTokenParameters -->
</transportSecurity>
</binding>
</customBinding>
</bindings>
<client>
...
</client>
</system.serviceModel>
I think you just use customBinding/security
, perhaps with an authenticationMode
of UserNameOverTransport
: 我认为您只是使用
customBinding/security
,可能是使用UserNameOverTransport
的authenticationMode
:
<system.serviceModel>
<bindings>
<customBinding>
<binding>
<security authenticationMode="UserNameOverTransport" />
</binding>
</customBinding>
</bindings>
</system.serviceModel>
Failing that, you could try adding the token manually to issuedTokenParameters
: 失败的话,您可以尝试将令牌手动添加到
issuedTokenParameters
:
<system.serviceModel>
<bindings>
<customBinding>
<binding>
<security authenticationMode="UserNameOverTransport">
<issuedTokenParameters tokenType="http://schemas.microsoft.com/ws/2006/05/identitymodel/tokens/UserName" />
</security>
</binding>
</customBinding>
</bindings>
</system.serviceModel>
(tokenType stolen from UserNameSecurityTokenParameters
) (从
UserNameSecurityTokenParameters
盗取的令牌类型)
To be honest, it's probably so much hassle that it's easier to just do it in code. 老实说,这可能很麻烦,以至于只需在代码中进行操作就更容易了。 If you need to to be different per environment, define the factory in the config and use DI to use it to create the binding.
如果每个环境需要不同,请在配置中定义工厂,然后使用DI来使用它创建绑定。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.