Bir*_*rey 3 federated-identity claims-based-identity wif ws-federation
我在 web.config 中有我的配置,它工作正常。
<configuration>
<system.identityModel.services>
<federationConfiguration>
....
</federationConfiguration>
</system.identityModel.services>
</configuration>
Run Code Online (Sandbox Code Playgroud)
如何将它从 web.config 移到自定义配置文件并从代码加载?
我想使用此配置的相同结构,以便在必须更改此配置文件时不必更改代码中的任何内容。
您可以从 global.asax 进入 WIF 事件
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
FederatedAuthentication.FederationConfigurationCreated += FederatedAuthenticationOnFederationConfigurationCreated;
}
Run Code Online (Sandbox Code Playgroud)
在该处理程序中,您可以在运行时调整配置。这里有一些代码可以给你一个想法。最终代码会更复杂。
private void FederatedAuthenticationOnFederationConfigurationCreated(object sender, FederationConfigurationCreatedEventArgs args)
{
var identityConfiguration = new IdentityConfiguration(loadConfig:false);
identityConfiguration.SecurityTokenHandlers.Clear();
//...
identityConfiguration.SecurityTokenHandlers.Add(new Saml2SecurityTokenHandler());
//...
var configuration = new FederationConfiguration(loadConfig: false)
{
CookieHandler = new ChunkedCookieHandler(),
//...
IdentityConfiguration = identityConfiguration
};
args.FederationConfiguration = configuration;
}
Run Code Online (Sandbox Code Playgroud)
如果您对给哪个对象赋予什么值有任何疑问,您可以随时临时切换回配置并通过同一事件检查运行时值。不要低估 WIF 开箱即用提供的配置的复杂性和丰富性。
一般来说,如果 web.config 仍然用于配置配置的某些更可变的部分,而代码用于更不可更改的部分,则您可能需要混合使用“代码配置”和“web.config 配置”...
| 归档时间: |
|
| 查看次数: |
1529 次 |
| 最近记录: |