私のMVCアプリケーションでは、フォーム認証を使用してユーザーを認証してから、System.IdentityModel.Services.SessionAuthenticationModule
でセッションを維持しています。MachineKeySessionSecurityTokenHandlerとアプリケーションの再起動の間にセッショントークンが期限切れになる
私がまだ必要ではない間に、System.IdentityModel.Services.Tokens.MachineKeySessionSecurityTokenHandler
を利用して、アプリケーションがウェブファーム(Dominick Baier hereで説明されているように)にうまく生きるようにしたいと思いました。
問題は、machineKeyベースの処理では、セッションがサーバマシンからマシンまで有効であるだけでなく、アプリケーションの再起動後も存続する必要があることです。しかし、私がアプリケーションを再起動したり再ビルドしたりするときはいつでも、ブラウザでアプリケーションを起動すると、クッキーは無効になり、認証画面にバウンスされます。もう一度認証されると、すべてが問題なくセッションが残ります。しかし、次回アプリが再起動したり再構築されたときに、私は再認証を余儀なくされます。
私はこれがWIFの一面であると確信していますが、私はここからどこに向かうべきか分かりません。私はMachineKeySessionSecurityTokenHandler
を拡張しなければならないことを恐れていませんが、私が進む前にここで何が起こっているのかを確認したいと思います。私は、デフォルトのSessionSecurityTokenHandler
は、その暗号化のためにアプリケーションプールからのいくつかの識別子と組み合わせてDPAPIを使用することを理解しているので、この場合には起こるだろうが、MachineKeySessionSecurityTokenHandler
の動作が私を困惑させる。 MachineKeySessionSecurityTokenHandler
が依存している再起動時に再作成されるアプリケーションの識別子がまだありますか?私はちょうど設定が不足していますか?ここで
私のweb.configファイルから関連部分です:
<configSections>
<section name="system.identityModel"
type="System.IdentityModel.Configuration.SystemIdentityModelSection, System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" />
</configSections>
...
<system.identityModel>
<identityConfiguration>
<securityTokenHandlers>
<remove type="System.IdentityModel.Tokens.SessionSecurityTokenHandler, System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<add type="System.IdentityModel.Services.Tokens.MachineKeySessionSecurityTokenHandler, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</securityTokenHandlers>
</identityConfiguration>
</system.identityModel>
...
<system.web>
<machineKey compatibilityMode="Framework45"
validationKey="E27893..."
decryptionKey="ABC..."
validation="SHA1" decryption="AES" />
<authentication mode="Forms">
<forms loginUrl="~/Account/Login"
timeout="10080" />
</authentication>
</system.web>
...
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="SessionAuthenticationModule"
type="System.IdentityModel.Services.SessionAuthenticationModule, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</modules>
</system.webServer>
これを動かします。私は今やっていることのために働いているようなものを手に入れようと苦労していました。問題は私のweb.configsの値を得ることでした。 web.configの設定を投稿していただきありがとうございます。この問題を解決するのに役立ちました。 Mike –
@indiecodemonkey - これがあなたを助けてくれてうれしい! –
フォーム認証を使わずにSessionAuthenticationModuleを使用してユーザーを認証する場合、共有WIFキャッシングを実装するために最後の部分が必要です(アプリプールのリセットでリセットされないなど)。それはSessionSecurityTokenCacheです。 MSDN上の例はここにありますhttps://msdn.microsoft.com/en-us/library/hh545457(v=vs.110).aspx –