7

理由はわかりませんが、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 が正しく初期化されないのはなぜですか?

4

3 に答える 3

14

私は、すでに動作しているプロジェクトと FederatedAuthentication.WSFederationAuthenticationModule でほぼ同じ動作をしています。

問題は、IIS Express から完全な IIS への切り替え (プロジェクト ファイルの不適切なマージ) を解決しました。

また、このモジュールをセクションだけでなく追加することもできます。

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

サンプルについては、このMSDN 記事を参照してください。

于 2013-07-16T11:55:53.507 に答える