理由はわかりませんが、FederatedAuthentication.SessionAuthenticationModule が NULL として解決され、ClaimsTransformer() モジュールを実行しようとするとアプリがクラッシュします。
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 :(
}
これが私の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>
問題なく(概念実証)プロジェクトでコードを実行しているため、これは私を夢中にさせています。この機能を機能させるために必要なのはそれだけのようですが、奇妙な理由で、実際のプロジェクトに実装しようとすると、私の FederatedAuthentication.SessionAuthenticationModule は常に NULL です。
ここで何が欠けていますか?何か案は?SessionAuthenticationModule が正しく初期化されないのはなぜですか?