FederatedAuthentication.WSFederationAuthentication

2019-01-28 02:17发布

I am trying to subcribe to RedirectingToIdentityProvider event in Application_Start() , but FederatedAuthentication.WSFederationAuthenticationModule is null

code

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

标签: asp.net wif
4条回答
萌系小妹纸
2楼-- · 2019-01-28 02:40

Make sure in your Global.asax you referencing the

System.IdentityModel.Services.WSFederationAuthenticationModule

and not:

Microsoft.IdentityModel.Web.FederatedAuthentication.WSFederationAuthenticationModule

The wrong (inconsistent between web.config and global.asax) reference will cause the WSFederationAuthenticationModule be null.

查看更多
ゆ 、 Hurt°
3楼-- · 2019-01-28 02:46

Try doing this - works for me.

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


void OnServiceConfigurationCreated(object sender, ServiceConfigurationCreatedEventArgs e)
{
    FederatedAuthentication.WSFederationAuthenticationModule.RedirectingToIdentityProvider += WSFederationAuthenticationModule_RedirectingToIdentityProvider;
} 
查看更多
淡お忘
4楼-- · 2019-01-28 02:50

It sounds like you may be missing the WSFederationAuthenticationModule in your configuration. Make sure you have this in system.webServer\modules:

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

And this in system.web\httpModules:

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

Read here for more information.

查看更多
叛逆
5楼-- · 2019-01-28 02:52

Here is a precision for .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>
查看更多
登录 后发表回答