我执行以下步骤:
AppStart
...
using System.IdentityModel.Services.Configuration;
using System.IdentityModel.Services;
protected void Application_Start()
...
FederatedAuthentication.FederationConfigurationCreated += FederatedAuthentication_FederationConfigurationCreated;
}
void FederatedAuthentication_FederationConfigurationCreated(object sender, FederationConfigurationCreatedEventArgs e)
{
// Replace the below with your implementation
throw new NotImplementedException();
}
Web.config
<configuration>
<configSections>
...
<section name="system.identityModel" type="System.IdentityModel.Configuration.SystemIdentityModelSection, System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
<section name="system.identityModel.services" type="System.IdentityModel.Services.Configuration.SystemIdentityModelServicesSection, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
...
<system.identityModel.services>
<federationConfiguration>
<cookieHandler/>
</federationConfiguration>
</system.identityModel.services>
</configuration>
我发现这篇文章在实现时非常有用。
http://dotnetcodr.com/2013/03/07/claims-based-authentication-in-net4-5-mvc4-with-c-external-authentication-with-ws-federation-part-1/
更新
我在system.identityModel 配置中也有以下内容。
<system.identityModel>
<identityConfiguration>
<claimsAuthenticationManager type="namespace.webproject.CustomClaimsTransformer,namespace.webproject" />
<claimsAuthorizationManager type="namespace.webproject.CustomAuthorisationManager,namespace.webproject" />
</identityConfiguration>
</system.identityModel>