What does FederatedAuthentication.SessionAuthenticationModule return NULL?

I'm not sure why, but my FederatedAuthentication.SessionAuthenticationModule resolves NULL and my application crashes when I try to run the ClaimsTransformer () module:

public void EstablishSession(ClaimsPrincipal principal) { var sessionToken = new SessionSecurityToken(principal, TimeSpan.FromHours(8)) { IsPersistent = false, // make persistent IsReferenceMode = true // cache on server }; FederatedAuthentication.SessionAuthenticationModule.WriteSessionTokenToCookie(sessionToken); // FederatedAuthentication.SessionAuthenticationModule == null and I throw an error :( } 

Here is what in my web.config:

 <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" /> </configSections> <system.web> <authentication mode="None" /> </system.web> <system.webServer> <modules runAllManagedModulesForAllRequests="true"> <remove name="RoleManager" /> <remove name="FormsAuthentication" /> <remove name="SessionAuthenticationModule" /> <add name="SessionAuthenticationModule" type="System.IdentityModel.Services.SessionAuthenticationModule, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> </modules> </system.webServer> <system.identityModel> <identityConfiguration> <claimsAuthenticationManager type="Web.Infrastructure.Authentication.ClaimsTransformer, Web" /> </identityConfiguration> </system.identityModel> <system.identityModel.services> <federationConfiguration> <cookieHandler requireSsl="false" /> </federationConfiguration> </system.identityModel.services> 

This drives me crazy, because I have the code working in the project (proof of concept) without any problems, and everything appears that I need for this functionality to work, but for some strange reason, when I try to implement our real project, my FederatedAuthentication.SessionAuthenticationModule is always NULL.

What am I missing here? Any ideas? Why is the SessionAuthenticationModule not initializing correctly?

+6
source share
3 answers

I have almost the same behavior with an already running project and FederatedAuthentication.WSFederationAuthenticationModule.

The problem was resolved when switching from IIS Express to full IIS (bad merging for the project file).

You can also try adding this module not only to the section, but:

 <system.web> <httpModules> <add name="SessionAuthenticationModule" type="System.IdentityModel.Services.SessionAuthenticationModule, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> 

You can refer to this MSDN article for a sample.

+11
source

I had this problem and I just solved it by adding the following to my web.config. It is worth a try if someone else has a problem.

  <system.webServer> <modules runAllManagedModulesForAllRequests="true"> <remove name="FormsAuthenticationModule" /> <add name="SessionAuthenticationModule" type="System.IdentityModel.Services.SessionAuthenticationModule, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"></add> </modules> </system.webServer> 
+1
source

Check web.config :

 <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" /> </configSections> <system.webServer> <modules> <add name="SessionAuthenticationModule" type="System.IdentityModel.Services.SessionAuthenticationModule, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> </modules> </system.webServer> <system.identityModel.services> <federationConfiguration> <cookieHandler requireSsl="false" /> </federationConfiguration> </system.identityModel.services> 
0
source

Source: https://habr.com/ru/post/949042/


All Articles