已經好長一段時間,有某幾隻程式不定期會冒出以下的錯誤訊息:
Event code: 4009
Event message: Viewstate verification failed. Reason: The viewstate supplied failed integrity check.

這些程式在測試環境及平常使用狀況都很良好。第一直覺是有人更動了ViewState的資料,但推測不會有人無聊到做這種沒意義的駭客工程。今天特地花了點時間去追這個問題,我的構想是從IIS Log中找出該使用者的全部操作歷程,想像一下他可能做了哪些事。

發現一件有趣的事,今早09:10只出現一筆POST記錄,但追溯00:00為止都看不到任何GET,再往前追一天,才看到同一User早上有一個GET及多個POST的記錄。

我推測是User在昨天早上開了IE連上網頁,按了幾次查詢,然後IE沒關放著,一直到今天早上再按一下查詢,結果就出錯。

ViewState有保存期限嗎? 印象中沒聽過,但用力Google的結果,找到了以下的KB,發現原來Worker Process Restart也會導致ViewState被判定無效!

http://support.microsoft.com/default.aspx?scid=kb;en-us;829743

Determine whether the problem is caused by worker process recycling
Consider the following scenario.
  • You are running ASP.NET under Microsoft Internet Information Services (IIS) 6.0.
  • The application pool is running under an identity other than the Local System account, the Network Service account, or an administrative-level account.
  • The validationKey attribute of the <machineKey> element is set to AutoGenerate in the configuration file.

In this scenario, the following procedure will cause a view state error to occur:

  1. A user browses a page.
  2. The worker process that hosts the ASP.NET application recycles.
  3. The user posts back the page.

我把會出問題的程式跟機器做了簡單的統計... 哈! 問題會固定出在幾台機器上,而這幾台機器有排定每天凌晨IISRESET(咳... 鋸箭法被發現了,不准再問細節)。

答案揭曉! Case Closed!


Comments

Be the first to post a comment

Post a comment