我对ASP中的AntiForgeryToken有问题.Net MVC.如果我在我的网络服务器上做了一个iisreset,用户继续他们的会话,他们就会跳转到登录页面.这并不可怕,但随后,防暴令牌爆炸,唯一的办法是再次启动浏览器上的cookie.
在版本1的测试版中,当我读回cookie时会出错,所以我在请求验证令牌之前会擦除它,但当它发布时,这个问题就被修复了.
现在,我想我会回到我的代码,修复测试版的问题,但我不能不认为我错过了什么.有没有更简单的解决方案,见鬼,我应该放弃他们的助手,从头开始创建一个新的吗?我觉得很多问题都是因为它与旧的ASP紧密相连.Net管道,并试图让它做一些它并不是真正设计来做的事情.
我查看了ASP的源代码.Net MVC 2 RC,代码似乎没有太大变化,所以虽然我还没有try 过,但我认为没有任何答案.
以下是异常的堆栈跟踪的相关部分.
Edit:我刚刚意识到我没有提到这只是试图在GET请求中插入令牌.这不是当您开始发布帖子时发生的验证.
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 useValidationSym算法)
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)