ASP.NetMVCのAntiForgeryTokenに問題があります。Webサーバーでiisresetを実行し、ユーザーがセッションを続行すると、ログインページにバウンスされます。ひどいことではありませんが、AntiForgeryトークンが爆発し、再び動作する唯一の方法は、ブラウザのCookieを吹き飛ばすことです。
バージョン1のベータ版では、Cookieを読み戻すときに問題が発生したため、検証トークンを要求する前にCookieをスクラブしていましたが、リリース時に修正されました。
今のところ、ベータ版の問題を修正したコードにロールバックすると思いますが、何かが足りないと思わずにはいられません。より簡単な解決策はありますか?彼らのヘルパーをドロップして、最初から新しいヘルパーを作成する必要がありますか?多くの問題は、古いASP.Netパイプラインに深く結びついていて、実際には設計されていないことを実行しようとしているという事実だと感じています。
ASP.Net MVC 2 RCのソースコードを調べましたが、コードがあまり変更されていないようですので、試していませんが、答えはないと思います。
例外のスタックトレースの関連部分は次のとおりです。
編集:これがGETリクエストにトークンを挿入しようとしているだけだとは言わなかったことに気づきました。これは、POSTキックオフを実行するときに発生する検証ではありません。
System.Web.Mvc.HttpAntiForgeryException: A required anti-forgery token was not
supplied or was invalid.
---> System.Web.HttpException: Validation of viewstate MAC failed. If this
application is hosted by a Web Farm or cluster, ensure that <machineKey>
configuration specifies the same validationKey and validation algorithm.
AutoGenerate cannot be used in a cluster.
---> System.Web.UI.ViewStateException: Invalid viewstate.
Client IP: 127.0.0.1
Port: 4991
User-Agent: scrubbed
ViewState: scrubbed
Referer: blah
Path: /oursite/Account/Login
---> System.Security.Cryptography.CryptographicException: Padding is invalid and
cannot be removed.
at System.Security.Cryptography.RijndaelManagedTransform.DecryptData(Byte[] inputBuffer, Int32 inputOffset, Int32 inputCount, Byte[]& outputBuffer, Int32 outputOffset, PaddingMode paddingMode, Boolean fLast)
at System.Security.Cryptography.RijndaelManagedTransform.TransformFinalBlock(Byte[] inputBuffer, Int32 inputOffset, Int32 inputCount)
at System.Security.Cryptography.CryptoStream.FlushFinalBlock()
at System.Web.Configuration.MachineKeySection.EncryptOrDecryptData(Boolean fEncrypt, Byte[] buf, Byte[] modifier, Int32 start, Int32 length, IVType ivType, Boolean useValidationSymAlgo)
at System.Web.UI.ObjectStateFormatter.Deserialize(String inputString)
--- End of inner exception stack trace ---
--- End of inner exception stack trace ---
at System.Web.UI.ViewStateException.ThrowError(Exception inner, String persistedState, String errorPageMessage, Boolean macValidationError)
at System.Web.UI.ViewStateException.ThrowMacValidationError(Exception inner, String persistedState)
at System.Web.UI.ObjectStateFormatter.Deserialize(String inputString)
at System.Web.UI.ObjectStateFormatter.System.Web.UI.IStateFormatter.Deserialize(String serializedState)
at System.Web.Mvc.AntiForgeryDataSerializer.Deserialize(String serializedToken)
--- End of inner exception stack trace ---
at System.Web.Mvc.AntiForgeryDataSerializer.Deserialize(String serializedToken)
at System.Web.Mvc.HtmlHelper.GetAntiForgeryTokenAndSetCookie(String salt, String domain, String path)
at System.Web.Mvc.HtmlHelper.AntiForgeryToken(String salt, String domain, String path)