FederatedAuthentication.WSFederationAuthenticationModule在运行时为null

时间:2012-01-20 05:28:14

标签: asp.net wif

我正在尝试订阅 Application_Start()中的 RedirectingToIdentityProvider 事件,但FederatedAuthentication.WSFederationAuthenticationModule为空

代码

protected void Application_Start()
{
 FederatedAuthentication.WSFederationAuthenticationModule.RedirectingToIdentityProvider += WSFederationAuthenticationModule_RedirectingToIdentityProvider;
}

4 个答案:

答案 0 :(得分:5)

尝试这样做 - 适合我。

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


void OnServiceConfigurationCreated(object sender, ServiceConfigurationCreatedEventArgs e)
{
    FederatedAuthentication.WSFederationAuthenticationModule.RedirectingToIdentityProvider += WSFederationAuthenticationModule_RedirectingToIdentityProvider;
} 

答案 1 :(得分: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" />

这是system.web\httpModules

<add name="WSFederationAuthenticationModule" type="Microsoft.IdentityModel.Web.WSFederationAuthenticationModule, Microsoft.IdentityModel, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

阅读here了解详情。

答案 2 :(得分:3)

这是.net 4.0的精度

<system.web>
    <httpModules>
          <add name="WSFederationAuthenticationModule" type="System.IdentityModel.Services.WSFederationAuthenticationModule, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
    </httpModules>
</system.web>
....
<system.webServer>    
    <modules>      
      <add name="WSFederationAuthenticationModule" type="System.IdentityModel.Services.WSFederationAuthenticationModule, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" preCondition="managedHandler" />      
    </modules>
</system.webServer>

答案 3 :(得分:2)

请确保在您的Global.asax中引用

System.IdentityModel.Services.WSFederationAuthenticationModule

而不是:

Microsoft.IdentityModel.Web.FederatedAuthentication.WSFederationAuthenticationModule

错误(web.config和global.asax之间的不一致)引用将导致WSFederationAuthenticationModule为null。