FederatedAuthentication.WSFederationAuthenticationModule在运行时为null

Voi*_*miX 5 asp.net wif

我试图在Application_Start()中订阅RedirectingToIdentityProvider事件,但是FederatedAuthentication.WSFederationAuthenticationModule为null

protected void Application_Start()
{
 FederatedAuthentication.WSFederationAuthenticationModule.RedirectingToIdentityProvider += WSFederationAuthenticationModule_RedirectingToIdentityProvider;
}
Run Code Online (Sandbox Code Playgroud)

小智 5

尝试这样做 - 适合我.

void Application_Start()
{
    FederatedAuthentication.ServiceConfigurationCreated += OnServiceConfigurationCreated;
}


void OnServiceConfigurationCreated(object sender, ServiceConfigurationCreatedEventArgs e)
{
    FederatedAuthentication.WSFederationAuthenticationModule.RedirectingToIdentityProvider += WSFederationAuthenticationModule_RedirectingToIdentityProvider;
} 
Run Code Online (Sandbox Code Playgroud)

  • 我认为`.SystemConfigurationCreated`在`System.IdentityModel.Services.FederatedAuthentication`(.NET 4.5实现)中不存在. (5认同)

Gar*_*ger 3

听起来您WSFederationAuthenticationModule的配置中可能缺少 。确保你有这个system.webServer\modules

<add name="WSFederationAuthenticationModule" type="Microsoft.IdentityModel.Web.WSFederationAuthenticationModule, Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" preCondition="managedHandler" />
Run Code Online (Sandbox Code Playgroud)

这在system.web\httpModules

<add name="WSFederationAuthenticationModule" type="Microsoft.IdentityModel.Web.WSFederationAuthenticationModule, Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
Run Code Online (Sandbox Code Playgroud)

阅读此处了解更多信息。