9

Windows Live と Google に対して Azure ACS を使用してきましたが、問題なく動作しています。昨夜、実行中のインスタンスを 1 つから 3 つにスケーリングしました。それ以来、サイトにアクセスする際の問題が報告されています。これは、かなり定期的に発生する次の例外にまで遡ります。

構成のどこかに問題があると想定していますが、何が欠けているのかはわかりません。マシンキーを設定します...

<machineKey decryption="AES" decryptionKey="F7_SOMETHING_SOMETHING_FA" validation="SHA1" validationKey="63_SOMETHING_SOMETHING_BF" />

誰でもこの問題に光を当てることができますか?

System.InvalidOperationException: ID1073: A CryptographicException occurred when attempting to decrypt the cookie using the ProtectedData API (see inner exception for details). If you are using IIS 7.5, this could be due to the loadUserProfile setting on the Application Pool being set to false.  ---> System.Security.Cryptography.CryptographicException: Key not valid for use in specified state.

   at System.Security.Cryptography.ProtectedData.Unprotect(Byte[] encryptedData, Byte[] optionalEntropy, DataProtectionScope scope)
   at Microsoft.IdentityModel.Web.ProtectedDataCookieTransform.Decode(Byte[] encoded)
   --- End of inner exception stack trace ---
   at Microsoft.IdentityModel.Web.ProtectedDataCookieTransform.Decode(Byte[] encoded)
   at Microsoft.IdentityModel.Tokens.SessionSecurityTokenHandler.ApplyTransforms(Byte[] cookie, Boolean outbound)
   at Microsoft.IdentityModel.Tokens.SessionSecurityTokenHandler.ReadToken(XmlReader reader, SecurityTokenResolver tokenResolver)
   at Microsoft.IdentityModel.Tokens.SessionSecurityTokenHandler.ReadToken(Byte[] token, SecurityTokenResolver tokenResolver)
   at Microsoft.IdentityModel.Web.SessionAuthenticationModule.ReadSessionTokenFromCookie(Byte[] sessionCookie)
   at Microsoft.IdentityModel.Web.SessionAuthenticationModule.TryReadSessionTokenFromCookie(SessionSecurityToken& sessionToken)
   at Microsoft.IdentityModel.Web.SessionAuthenticationModule.OnAuthenticateRequest(Object sender, EventArgs eventArgs)
   at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

注: コンテキスト用です。これは Windows Azure Web ロールで実行されており、MVC 4 です。

4

3 に答える 3

7

スケール アウトが完了し、アプリケーションがロード バランサーの背後でホストされているため、ユーザーがサーバー A に移動し、サーバー A の DPAPI によって保護されたセッション Cookie を取得した可能性がありますが、サイトを閲覧し続けているためです。ロード バランサーはサーバー B で実行するように要求をリダイレクトします。この場合、サーバー B には一致するマシン キーがないため、セッション Cookie を復号化できず、上記のエラーがスローされます。この問題を解決する 3 つの方法を次に示します。

Windows Identity Foundation (WIF) は帯域外ランタイムであり、クレーム対応アプリケーションで使用できるようにコンピューターにインストールする必要があります。デフォルトでは、WIF は Windows Azure インスタンスにインストールされません。クラウド クレーム対応アプリケーションを実行するには、Windows Azure インスタンスで WIF ランタイムを使用できるようにする必要があります。これを行う最も簡単な方法は、展開パッケージに WIF アセンブリを含めることです。

Windows Azure 展開パッケージに WIF アセンブリを含めるには

  1. ソリューション エクスプローラーで、クレーム対応アプリケーションを見つけます。
  2. 参照フォルダーを展開します。
  3. References フォルダーで Microsoft.IdentityModel アセンブリを見つけます。
  4. アセンブリを右クリックし、[プロパティ] をクリックします。
  5. プロパティ ウィンドウで、Copy Local を True、Specific Version を False に指定します。

既定では、WIF はデータ保護アプリケーション プログラミング インターフェイス (DPAPI) を使用して Cookie を暗号化して保護します。DPAPI は Windows Azure では使用できません。クラウド クレーム対応 Web アプリケーションが Windows Azure にデプロイされたときに正しく機能するようにするには、RSA を使用して Cookie 暗号化機能を追加する必要があります。

RSA を使用して Cookie を暗号化するには

  1. ソリューション エクスプローラーで、クラウド クレーム対応 Web アプリケーションを見つけます。
  2. global.asax ファイルの背後にあるコードである global.asax.cs ファイルを Visual Studio エディターで開きます。

次の宣言を追加します。

using Microsoft.IdentityModel.Tokens;
using Microsoft.IdentityModel.Web;
using Microsoft.IdentityModel.Web.Configuration;

次のコードを追加します。

void OnServiceConfigurationCreated(object sender, ServiceConfigurationCreatedEventArgs e)
{
    //
    // Use the <serviceCertificate> to protect the cookies that are
    // sent to the client.
    //
    List<CookieTransform> sessionTransforms =
        new List<CookieTransform>(new CookieTransform[] {
        new DeflateCookieTransform(), 
        new RsaEncryptionCookieTransform(e.ServiceConfiguration.ServiceCertificate),
        new RsaSignatureCookieTransform(e.ServiceConfiguration.ServiceCertificate)  });
    SessionSecurityTokenHandler sessionHandler = new SessionSecurityTokenHandler(sessionTransforms.AsReadOnly());
    e.ServiceConfiguration.SecurityTokenHandlers.AddOrReplace(sessionHandler);
}

void Application_Start(object sender, EventArgs e)
{
    FederatedAuthentication.ServiceConfigurationCreated += OnServiceConfigurationCreated;

詳細については、http: //msdn.microsoft.com/en-us/library/hh289318.aspxを参照してください。

于 2012-12-19T13:27:30.403 に答える
2

farmこれは、環境で WIF を使用する場合の一般的な例外です。ポイントは、デフォルトの動作では DPAPI を使用して Cookie を暗号化することです。ただし、DPAPI は MachineKey にバインドされています。

Global.Asax に小さな変更を加え、RSA Crypto サービス プロバイダーを使用して FedAuth Cookie を暗号化/復号化する必要があります。それを達成する方法については、この記事をご覧ください。

于 2012-12-19T13:28:59.917 に答える
1

Windows Azure Web サイト インスタンスとクラウド サービスとしてデプロイされた MVC 4 アプリで ACS を利用しようとしたときに、同様の問題に遭遇しました。以下は、問題の解決に役立ちました。 http://msdn.microsoft.com/en-us/library/hh568644.aspx

一番下までスクロールし、SessionSecurityTokenHandler を削除して MachineKeySessionSecurityTokenHandler に置き換える例を見つけます。

于 2013-09-16T17:11:27.940 に答える