2013-01-22 178 views
1

我得到的驗證失敗在ASP.NET 4.0 URL路由

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. 

臭名昭著的錯誤經過廣泛的搜索,我無法找到任何解決我的具體問題。我在.NET 4中使用URL路由,但我沒有使用MVC。我發現的所有問題/解決方案都是類似的(由於URL路由),所以在MVC中提供瞭解決方案,但不是在常規的ASP.NET Web窗體中。

的堆棧溢出問題​​筆記:

It seems to be related to the number of sub-paths in the url. If there are at least 2 sub-paths the viewstate validation fails.

在測試這個理論,我是能夠提供一個快速和骯髒的工作,各地通過簡單地從

Module/Search/Results

改變我的路線到

Module/SearchResults

暫時解決了這個問題,但是,那篇文章中的答案都沒有幫助。

有趣的事情我發現,錯誤可以在IE9中重現,但不能在Chrome 24.0.1313.52m中重現。這導致我相信這個錯誤是瀏覽器特定的,所以我嘗試爲我的網站設置NoCache,但無濟於事,Chrome仍然工作,IE9仍然拋出ViewState錯誤。

爲了重現該問題,這裏有一些關鍵因素,我的環境:

Windows 7 64-bit 
IIS 6.1 SP 1 
Local Web Project (VS 2010) 
Nested Master Pages (3 levels) 
URL Routing (defined in Global.asax) 
Page contains a GridView with a TemplateField. 
GridView has PagerSettings defined. 
Links causing the error are within the TemplateField. 
Links outside of the GridView do not cause the error. 

重現步驟如下:

User browses to page "~/Module/Search/Results" (from link or directly doesn't matter) 
User clicks on a button that posts back and causes a redirect to another page "~/Module/DoSomething" 
User presses the Back button in the browser which takes them back to "~/Module/Search/Results" 
User then proceeds to press a button that causes a post-back which immediately causes the error. 

UPDATE: Added information in the key factors regarding the layout of the page.

我怎樣才能解決這個問題問題,以便我可以在網頁的網址中有2個或更多子路徑,而不會在用戶返回頁面時導致錯誤,然後生成另一個帖子?

+0

我設法找到這個:http://blogs.msdn.com/b/tom/archive/2008/03/14/validation-of-viewstate-mac-failed-error.aspx。這有幫助嗎(它涉及到webforms)。 –

+0

不幸的是,沒有。在ViewState加載之前用戶按下按鈕(我給了足夠的時間加載)似乎並不是一個問題。但是,將EnableViewStateMac設置爲false會產生錯誤「狀態信息對於此頁無效,並且可能已損壞。」正如你的鏈接在開頭提到的那樣,但其餘部分似乎並不適用。 (嘗試了您的鏈接中的基本頁面和其他建議) –

回答

0

我明白了!

在試圖解決我在那裏得到的錯誤

Microsoft JScript runtime error: 'WebForm_FireDefaultButton' is undefined

問題

我發現一篇文章,說我需要添加以下到我的路由表的頂部

routes.Ignore("{resource}.axd/{*pathInfo}");

這似乎解決了我在尋找的問題以及這個問題中的問題。