7

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;
}
VoimiX
  • 1,180
  • 3
  • 16
  • 31

4 Answers4

6

Try doing this - works for me.

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


void OnServiceConfigurationCreated(object sender, ServiceConfigurationCreatedEventArgs e)
{
    FederatedAuthentication.WSFederationAuthenticationModule.RedirectingToIdentityProvider += WSFederationAuthenticationModule_RedirectingToIdentityProvider;
} 
Shaun Venus
  • 136
  • 1
  • 3
  • 6
    I think `.ServiceConfigurationCreated` is not present in `System.IdentityModel.Services.FederatedAuthentication` (the .NET 4.5 implemenation.) – Carl G Aug 08 '13 at 21:44
4

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>
Guish
  • 4,968
  • 1
  • 37
  • 39
3

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.

3

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.

Garrett Vlieger
  • 9,354
  • 4
  • 32
  • 44